Re: disowning a process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the reply!

Well this seems straight-forward enough, but it doesn't seem to work for me.. see if I have everything straight..

#include <unistd.h>
#include <stdio.h>
int main()
{
   if(fork())
   { /* parent */
      sleep(15);
   }
   else
   { /* child */
      printf("setpgrp returned: %d\n",setpgrp());
      sleep(5);
   }
}

I run the program.. setpgrp is returning zero.. then I quickly look at the ps listing.. the child's pid is still the parent's, but that may be okay.. Then after 5 seconds when the child exits.. I do the ps again and I do still see that the child is now defunct.. the desired effect is that the child would go away because I don't care what the exit status was. I was thinking that if init could become the parent of the newly forked child, then it would clean it up when it exits.

Any ideas?

-- Davy

[email protected] wrote:

Davy,
After you fork the process, use setpgrp() to make the process the head of
it's own process group.
check man -S2 setpgrp for details.


Hi,  I'm not sure if there's a posix way of doing this, but wanted to
check if there is a way in linux.

I want to have a daemon that fork/execs a new process, but don't want
(for various reasons) the responsibility for cleaning up those process
with the wait() function family.   I'm assuming that if the init process
became the parent of one of these forked processes, then it would clean
them up for me (is this assumption true?).    Besides the daemon process
exiting, is there a way to disown the process on purpose so that init
inherits it?

Thanks,
  Davy

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/




-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux