Monday, October 25, 2010

Orphan Process

Orphan Process

As the name suggest the orphan process means, some process has no parent. Look unlike you pthreads, Unix process are hierarchical in nature. Parent process expect he return status from the child process. Receiving this exit status the child process resources are freed.

Now if, when child exits and its parent is not there(its dead) to collect the exit status we will call it orphan process.

If No parent is there then by default process id 1 will become the parent. It will collect the status of the process.


https://docs.google.com/document/edit?id=1jl3mwh5s0W5wOH2J2bUed1NqlQ2i74a0P1KyI57P2nY&hl=en#

Unix Basic stuff

Very Basic Stuff

1) To check process Id getpid()

2) To check process Id of parent process getppid()

3) To check process table “ps -el”

4) They say swapper process or scheduler process is the first process created with process Id 0. This process is responsible for allocating memory and scheduling process.

5) In program below
int main()
{
int pid;
pid = fork ();
if(pid ==0)
{
// this will be child process
}
else

{
//this will be the parent process
}
}
All I wanted to communicate is that for return 0 to the child process and newly created Process Id to the parent process. As it happens every where if system call fails it will return -1.
You could remember this 0 return value from the fact that. Every thing present after the fork() is executed for the child process. So effectively the statement “pid = fork()” will never get executed for the child hence the value will be 0.

I would just like to add one more thing, you can add to you knowledge, when fork is call say all the data sections are copied so some different place and whatever instructions present after the current instruction will work as child process.