in reply to http waits on process

The problem is that when you call
`$myscript &`;
You are essentially calling
`sh -c '$myscript &'`;
In other words... you are waiting for the shell process to terminate... but the shell process (if it were interactive) would have returned a prompt imediately after firing off $myScript.

If you really want to fire off a background job from a perl process, and don't care about the output (btw: backticks imply that you do care about the output, but continuing imediately imply that you do not care about the output)... then you should do something more like this:

my $pid = fork; die "Could not fork: $!" unless defined $pid; if (!$pid) { exec $myScript; }
Which is somewhat akin to what the shell does when you launch the program foo by typing:
[user@host]$ foo &
------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re: Re: http waits on process
by hotshot (Prior) on Jan 14, 2004 at 08:03 UTC
    As I said, the problem happened only when I did it from cgi script through the web page, when I tried it from a regular script, I had no problem.
    Additionally, I already tried the solution you suggested (fork and exec), and still I get the same problem, I think it something related to apache that waits for stdout or someting (closing stdout, didn't work also).
    Do you have another idea?