LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-24-2008, 03:04 AM   #1
sankumar
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Rep: Reputation: 0
Smile 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
 
Old 12-24-2008, 03:20 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by sankumar View Post
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().
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a process using fork()? Ashkan_s Programming 5 08-22-2008 11:46 AM
what happens if i create a thread and then fork the process? Thinking Programming 7 10-31-2005 02:22 PM
collecting data from fork process frostmagic Programming 5 12-28-2003 01:55 PM
how to fork a process? Punker99 Programming 2 07-28-2003 11:21 AM
fork() by Process 0 Manish Programming 0 02-23-2002 05:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration