Re: disowning a process

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

 



On Fri, 2005-05-27 at 14:05 -0500, Davy Durham wrote:
> Davy Durham wrote:

> I added "waitpid(pid,NULL,0);" after the outer-most if.. which is where 
> the grand parent cleans up the pid of the intermediate parent. 

That's correct.

> 
> However, now trying the daemon() function..  which seems to work the 
> same way.. it definately leaves a pid around.. so I guess you really 
> need to do a wait() in the parent after forking.. however you don't know 
> exactly which pid to wait for so you might be reaping some other child 
> you've previously spawned.. 

The daemon function is really just the inner fork and setsid. So with
using the daemon function it looks like this:

       if ((pid = fork()) < 0) {
                perror("fork");
        } else if (!pid) {
                if (daemon(0,0) < 0) {
                        exit(-1);
                }
		/* daemon code here */
		exit(0);
        }

        waitpid(pid,NULL,0);

-- Steve


-
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