in reply to 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.
Unfortunately that doesn't work. As soon as the main program (the one that did the forking) finishes running, the child process (the one that got forked) gets reaped.
I even tried modifying that code slightly to incorporate the previous suggestion of using Proc::Daemon::init. It doesn't matter, the child still dies. Is it possible that this is simply something that can only be done in sh and not in Perl?
Here is my test code (based on your suggestion):
a.pl :
b.pl:#!/usr/local/bin/perl my $pid = fork(); if ($pid == 0) { # This is the child process. # exec() the external program. exec("./b.pl &") or die "could not exec my_program: $!"; } elsif (!defined($pid)) { die "could not fork"; } # Everything below here is the parent process print "This is the parent process\n";
#!/usr/local/bin/perl use Proc::Daemon; Proc::Daemon::init; open ( OUT, ">b.out" ); while ( 1 ) { print OUT `/bin/date`; sleep( 2 ); }
I found that a.pl is calling b.pl, which is outputing the present time to b.out. But then, a.pl exits out, and so does b.pl. This is not the desired result. By the way, I'm doing this on FreeBSD 4.1.1 if that makes any difference.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Starting a process in the background that lives after perl dies.
by DrManhattan (Chaplain) on Nov 08, 2001 at 23:51 UTC | |
by ehdonhon (Curate) on Nov 09, 2001 at 01:09 UTC |