in reply to Re: Re: Starting a process in the background that lives after perl dies.
in thread Starting a process in the background that lives after perl dies.

Here's the test code I used:
#!/usr/bin/perl -w # forker.pl use strict; my $pid = fork(); if ($pid == 0) { exec("/tmp/busy_wait.pl"); } elsif (!defined($pid)) { die "could not fork"; } print "This is the parent process\n";
#!/usr/bin/perl -l # busy_wait.pl while (1) { print "Busy!"; sleep 2; }
When I execute forker.pl, I get this output:
[matt@megatron ~]$ /tmp/forker.pl Busy! This is the parent process [matt@megatron ~]$ Busy! Busy! Busy!
The parent dies, and I get my shell prompt back, but the busy_wait.pl child lives on until I purposefully kill it.

-Matt

Replies are listed 'Best First'.
Re: Re: Re: Re: Starting a process in the background that lives after perl dies.
by ehdonhon (Curate) on Nov 09, 2001 at 01:09 UTC
    Hi, thank you

    You were absolutely right.. that does work just like you said.

    Here's an element of the puzzle that I left out, and this is where I was getting caught.. this entire thing is running through xinetd. And even though the parent was dieing off, the child still was keeping the standard file discriptors open. As a result, my client that was waiting for an EOF on the socket was never getting it. DOH!

    So when I took what I learned from here and the example code and then applied it directly into the real code it worked perfectly as soon as I let my child run Proc::Daemon::Init, which closed the file handles for me.

    Thank you everybody for helping me figgure this one out!