LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Change in Process Id after fork (https://www.linuxquestions.org/questions/programming-9/change-in-process-id-after-fork-692684/)

sankumar 12-24-2008 03:04 AM

Change in Process Id after fork
 
Hi,
Why Process Id(PID) is incremented 1 after creating a child process?
Consider the following and its corresponding outputs.

#include<stdio.h>
main()
{
int pid;
int pid_fork;
pid = getpid();
printf("\n Process Id is %d \n",pid);
pid_fork = fork();

if(pid_fork !=0)
printf("\n Process Id after fork %d \n",pid_fork);
}

Output
Process Id is 28770
Process Id after fork 28771

Thanks in advance

Hko 12-24-2008 03:20 AM

Quote:

Originally Posted by sankumar (Post 3385853)
Hi,
Why Process Id(PID) is incremented 1 after creating a child process?

It's not: fork() returns the PID of the new process just created, not the PID of the process that called fork().


All times are GMT -5. The time now is 02:56 PM.