Sub4Sub network gives free YouTube subscribers
Get Free YouTube Subscribers, Views and Likes

Process creation and termination - fork() exec() wait() and exit()

Follow
Shahid Nihal

Process creation is done in UNIX system with the help of the fork() command. The process which creates another process is called the 'parent' process and the process which gets created is the 'child' process.
fork() creates a duplicate child process same as parent the program and data is copied to child process and both these would run concurrently.
exec() is used to overlay a block of code with a new block of code this way the parent and child can run 2 different programs at the same time
wait() is called by parent and this suspends parent process and it waits till child completes
exit() is called to properly terminate the process by deallocating the resources which were allocated for the process.

If parent does not call wait(), then it would continue running without waiting for the child. If child terminates by calling exit(), then since parent does not wait for this, there is no one to catch its exit status. The child process has terminated, but its entry in process table exists. Removal of this entry is done by the parent process, but since parent doesn't wait(), it doesnt receive the exit status of child and hence doesnt remove the child process entry from the table. Such processes are called ZOMBIE processes.

If parent does not call wait(), but terminates by calling exit(), then parent is no more and if child is still running then such child process becomes an ORPHAN process.
#fork()
#exec()
#wait()

posted by ShooroHedgecv