jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks,

I have need to 'spawn' an external Perl process from within a CGI::Application based web-app under mod_perl.

I cannot figure out how to 'run and detach'. I need to pass a list to the external programme then have it just go off and do its thing. It may take some hours for its work to be done. It can report via a log file or a semaphore file, I do not want to wait for it to return.

How do I do this?

jdtoronto

  • Comment on Starting another programme from mod_perl

Replies are listed 'Best First'.
Re: Starting another programme from mod_perl
by matija (Priest) on Apr 02, 2004 at 19:53 UTC
    You could just fork it off like this:
    unless (fork) { exec("/some/long/running/program"); # exec never returns here }
      That may cause issues... you may need to close STDOUT as well, and possibly STDERR. I know you need to do this from a CGI, otherwise the child can cause the process to stay open.

      It seems there is also a call to detach a process from a process group, just for an extra measure of independance, but I don't remember what that call is.

                      - Ant
                      - Some of my best work - (1 2 3)

Re: Starting another programme from mod_perl
by BUU (Prior) on Apr 02, 2004 at 22:01 UTC
    Back ticks and background? `/my/long/process &`;
Re: Starting another programme from mod_perl
by edoc (Chaplain) on Apr 03, 2004 at 13:27 UTC