When ever we are running two process together using fork() in our main program , and if parent process finishes before child process , Parent process is terminated by shell and Child is adopted by INIT process whose PID is 1 so child PPID also becomes 1 after termination of parent process and Child become ORPHAN. IT becomes shell hang/halt state. To Overcome this problem we use WAIT() system call which will pause the execution of parent process untill child process finishes execution. The argument of WAIT() is ptr to the location where the exit code of child process is stored. When the exit code of child process becomes visible to the parent process. Parent comes out of pause state and Execute termination section of child process. After that shell executes Termination section of process. This can be checked by using MACRO wait()--------for pause.----------Return PID of child process WIFEXITED(stat_val)------- Non zero if child terminates normally. WEXITSTATUS(stat_val)-------- will return child exit code if child terminates normally by using EXIT call . ~ ~
In the latest linux systems which have kernel versions around4.8 , the child is not adopted by the in it process . It is adopted by a process named sys user which have a PPID of 1122 something. And this PPID varies according to linux versions like in KALI, PPID was around 960 something and in XUBUNTU and UBUNTU its 1122.
In newer kernal systems 4.4 + (as i have seen) ..the traditional init process (PID 1) does not adopt the orphan process, but that PID is not same, it changes.
1330 ? Ss 0:00 /sbin/upstart --user (This is the result from UBUNTU (4.4))
REASON:
The init (or Initialization) process is the first process to run (hence pid 1) but in recent years there have been changes in the way an orphan process is adopted...it is adopted by some daemon and different distros have a slightly different taste to it, hence a change in PID as well, which also changes unlike PID 1 of init process.
In case of some other systems like fedora kali etc....we have a different name "systemd" and others as given below
Upstart – A init replacement daemon implemented in Ubuntu GNU/Linux and designed to start process asynchronously.
Epoch – A init replacement daemon built around simplicity and service management, designed to start process single-threaded.
Mudar – A init replacement daemon written in Python, implemented on Pardus GNU/Linux and designed to start process asynchronously.
systemd – A init replacement daemon designed to start process in parallel, implemented in a number of standard distribution – Fedora, OpenSuSE, Arch, RHEL, CentOS, etc.