in reply to Re: Have perl to start another perl script
in thread Have perl to start another perl script

I would like to "daemonizat" the other perl script and completly dissociate it from the parent script. But save the child pid to a file. I tried the following but the system returns 0 as pid.
$pid = system("other.pl $IPaddress &"); #my $pidfile = "/home/ember/devices/$Macaddress/$pid.pid"; #open (FILE, "> $pidfile") or die "Can't open file $pidfile\n"; #close FILE;

Replies are listed 'Best First'.
Re^3: Have perl to start another perl script
by BrowserUk (Patriarch) on Jul 27, 2007 at 10:55 UTC

    You can start the script and obtain the pid using a piped open.

    my $pid = open KID, "| /path/to/your/perl theScript.pl" or die ... print KID $IPAddress; close KID;

    I'm not sure if there are any caveats with this on your platform.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Have perl to start another perl script
by Corion (Patriarch) on Jul 27, 2007 at 10:43 UTC

    system always returns 0 on successful launch. I recommend you do all the pid-saving in a wrapper shellscript (or Perlscript) around your child program:

    #!/usr/bin/perl -w use strict; my $pid = $$; my ($IPaddress) = @ARGV; # Save our PID into the pidfile: my $pidfile = "/home/ember/devices/$Macaddress/$pid.pid"; open (FILE, "> $pidfile") or die "Can't create file $pidfile: $!\n"; print FILE "$pidfile\n"; close FILE; # and replace ourselves with the real program, which gets the same PID + as we had: exec 'other.pl', $IPaddress;
      The code worked fine but since it's a .cgi that starts the second script it's started as apache and after 120 sec the process is killed due to inactivity (send/reciv).

      Any one that has a solution to this?
    • Start as other user
    • remove timeout in httpd.conf?