The process creation consists of three phases:
Fork : When a process is said to be forked, it creates a copy of the process. The new process will have a new PID.
Exec: Just creating a new process is not sufficient to execute it. The child process will require to overwrite the code and data of the parent process. This is known as ‘exec’. Note that the no new process is created here. This is just a mechanism to execute the process.
wait: The parent process would call ‘wait’ system call, which would suspend its execution and wait till the child process is complete.
One of the best example of process creation is the logging process.
In a multi user system, once system boots up, process 0 which is part of kernel process forks the init process and becomes the swapper process. The init process then spawns the getty process (which is get terminal- the terminal process). The getty process then execs the login program which waits till the user enters credentials which it validates. If login is successful, it execs the shell program else it exits and the init program again forks and creates the getty process. The below flow diagram would give a clear picture.
No comments:
Post a Comment