wait() system call
⚙️ The wait() System Call
Purpose:
The wait() system call is used by a parent process to pause execution until one of its child processes terminates.
This ensures synchronization — the parent process continues only after the child has completed its work.
Syntax:
-
Return value:
-
Returns the process ID of the terminated child on success.
-
Returns
-1if there are no child processes.
-
-
Parameter:
-
statusis an integer pointer used to store the exit status of the child. -
You can pass
NULLif you don’t need it.
-
Behavior:
-
When the parent calls
wait(), it is blocked until a child process finishes execution. -
Once the child terminates, the parent resumes.
-
This avoids zombie processes, since
wait()collects the child’s exit status.
Example:
Output:
✅ Here, wait() ensures synchronization — the parent executes only after the child finishes.
Comments
Post a Comment