Home > C/C++ > child process and setsid()

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. */
execlp (“/bin/sh”, “sh”, “-c”, program, NULL);
exit (1);

-Shoaib Mir

Categories: C/C++ Tags: , ,
  1. Saira Andleeb
    January 9, 2009 at 7:01 pm

    :O … i never expected such blogging from you! 🙂

  2. January 10, 2009 at 2:42 am

    its just in the spirit of being a opensource developer, so trying to put my experience back so that it might help someone 🙂

  3. d-machine
    January 20, 2009 at 1:54 am

    O ae kee ho rehya ae? 😀

  4. January 20, 2009 at 2:26 am

    bus yar back to some old stuff that I used to do 😛

  5. Farhan
    February 9, 2009 at 11:54 am

    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* :$ …

  6. February 9, 2009 at 9:39 pm

    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.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: