Results 1 to 5 of 5
Hai
Im doing a study in how to use fork(). I test a simple code and it is as follow
Code:
int pid;
pid = fork();
printf("%d", pid);
sleep(20);
Then ...
- 02-04-2009 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 19
fork() basics
Hai
Im doing a study in how to use fork(). I test a simple code and it is as follow
Then i compile and run the code, it sleeps for 20 seconds so that i can view the process list (ps -ux). My new process ID created which is also printed out to the screen was 4744. However, when I view the process list, i also found another process id running together with the new process id created and this process id is 4743. Im not sure where this process id comes from. Hope can get some advice for you guys. Another thing, what does setsid() do and what is the difference if I use the data type of the process id as int with data type pid_t. ThanksCode:int pid; pid = fork(); printf("%d", pid); sleep(20);
- 02-04-2009 #2
open a terminal and info fork or man fork...it will explain whats going on...Hope this helps..Gerard
welcome to thelinux forums
- 02-05-2009 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 19
Thanks gerard. I have gone through the man page before I post this question. I have certain view on my understanding but the reason I post this question is to certify my uncertainty. However, I now understand what is going on behind the scene. It is not because of the fork process but it was just a silly thing i missed which is the command running in the terminal is also a process with a unique process ID. Sorry for giving basic questions.
But then I'm not quite clear about setsid() function. Im not sure, when we open a new session ID for a process, does it exits from the terminal shell parent and will directly be a child of init() or it will remain under shell parent but it has its own independant group ID. I just need to clear up my understanding the hierarchy of the parent child processes. Thanks again.
- 02-05-2009 #4
Try this link...it explains a use of setsid()...
Linux Daemon Writing HOWTO
- 02-05-2009 #5Just Joined!
- Join Date
- Dec 2007
- Posts
- 19
Thanks gerard. The link really helps. Thanks again


Reply With Quote