child process and setsid()
I was trying to run a new process within the child process after the fork was successful and when ever I tried to run the process using execlp, as soon as the parent exited the child also did quit as well. This was getting very annoying and so I started googling the problem out and “setsid()” function was my friend in this case. With my final code looking like this:
pid_t pid;
pid = fork ();
if (pid == 0)
{
/* Child process. */
setsid();
execlp (“/bin/sh”, “sh”, “-c”, program, NULL);
exit (1);
}
-Shoaib Mir
shoaibmir[@]gmail.com
:O … i never expected such blogging from you!
its just in the spirit of being a opensource developer, so trying to put my experience back so that it might help someone
O ae kee ho rehya ae?
bus yar back to some old stuff that I used to do
You can have the parent wait for the child to exit as well using some wait function… this is what we did in uni
…
i remember it *a little* :$ …
I am talking about something else here
Basically it was the child process taking the same process id as that of parent which I didnt want it to take as I didnt want the child process to exit even if the parent has died.