in reply to spawning Perl scripts

I think some people reading awkmonk's post are missing an important factor... the secondary process is being spawned from a CGI script, which creates problems using the exec and system methods everyone has described already.

exec: "The exec function executes a system command and never returns."
system: "the parent process waits for the child process to complete."

For Win32:
The exec method would cause the script to terminate immediately, which means nothing past the exec() line in the original CGI process would be executed.
The system command would cause the script to hang and wait for the 3 hour process to complete, most likely causing a CGI timeout.

Neither of these are very viable options for awkmonk's problem because it needs to be multi-platform and on Win32 the originating CGI process would never run to completion... it would either exit at exec() or hang for 3 hours at system(), however... the sub-process would be spawned and continue running

Replies are listed 'Best First'.
Re: spawning Perl scripts
by Abigail-II (Bishop) on Mar 28, 2003 at 17:46 UTC
    That's why you fork first, an extremely common action to take before an exec.

    Abigail

      True, this will work in Win32 from the command line. However, when attempting to use a fork/exec solution through an IIS server, the parent still hangs and waits for the child to finish.

      The output I get is:
      Fri Mar 28 12:33:52 2003: Hello from the parent (473)! Fri Mar 28 12:33:52 2003: Hello from the child (-480)! Fri Mar 28 12:33:52 2003: Goodbye from the parent (473)!
      However, there is a thirty second pause between the display of 'Hello from the child' and 'Goodbye from the parent.' The machine thinks the parent process is done (timestamps), but server keeps crunching until the child terminates, only then does it display whatever is past the exec in the parent.

        Reason number #2647 to not use Windows.

        Abigail

Re^2: spawning Perl scripts
by mark4 (Acolyte) on Mar 23, 2015 at 12:34 UTC

    For Windows OS, I don't see a downside to:

    $cmd = "start perlprog.pl > file.log"; system ($cmd);

    This "system" command should return just after the process is started. One downside is that you will get another cmd window pop up.