Monday, October 25, 2010

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.



No comments: