Sleep() and exit() system calls are commonly used in Operating System labs for process management. These calls are essential to the functioning of the OS lab.

Sleep system call allows a process to take a snooze and chill for a bit, while the exit system call is like saying "See ya" to the process. When the process is done with its job, it can use the exit call to peacefully bow out. Zero means everything went smooth, non-zero means there was a hitch. Just like saying goodbye after a job well done or a bit of trouble. πŸ˜΄πŸ‘‹

Key Takeaways πŸ“

  • Sleep System Call: Keeps a running process in sleep state for a specified time in seconds, allowing the CPU to be allocated to other processes during that sleep time period.
  • Example Program: Demonstrates the usage of the Sleep System Call and the Fork system call to distinguish between child and parent processes.
  • Exit System Call: Used to terminate a process in the operating system by specifying the program’s completed execution.

In this video, we are going to discuss the Sleep System call and exit system call. The Sleep System call allows a process to relinquish the CPU and enter a sleep state for a set period, while the exit system call is used to terminate a program, indicating successful or error conditions. The Sleep System call keeps a running process in sleep state for a specified time in seconds, allowing the CPU to be allocated to other processes during that sleep time period. πŸ•‘

Example Program for Sleep System Call πŸ’»


| #include <stdio.h> | 

|---|
| #include <unistd.h> |

Here, we have a program that demonstrates the usage of the Sleep System Call and Fork system call to distinguish between child and parent processes.


The Fork system call returns 0 for the child process and a positive number for the parent process. If the obtained value is 0, it represents the child process which will then get executed, while the parent process executes otherwise. Once the Fork system call is executed, the for-loop displays numbers from 0 to 10 with a 5-second delay between each iteration using the Sleep System call. ✨

Output of Example Program πŸš€

Child ProcessParent Process
0I am parent process
1Every 1 second: I = 6
2Every 1 second: I = 7
3Every 1 second: I = 8
Every 1 second: I = 9

The exit system call is utilized to terminate a process, indicating its completed execution. A non-zero value indicates an error condition, while zero indicates a successful execution. In this video, we explored the functionalities of both the Sleep and Exit System calls in the operating system. πŸ›‘

About the Author

Sudhakar Atchala
135K subscribers

About the Channel:

This channel contains educational videos which helps the students for their self learning.
Share the Post:
en_GBEN_GB