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

Hi All
I have a cgi file which calls a perl script. This perl script takes very long to execute. I want to run this script in a background and when the results are ready then an email will be sent to the user
code in cgi
$cmd =perl perlscript.pl arg1 arg2 &
system ($cmd)
ps i also tried exec($cmd)
When I run cgi. It calls the script but the browser continues to work till the perl script is done with its work
Please suggest how should I break the connection of cgi and the perl script

Thank you

Replies are listed 'Best First'.
Re: How to run a process in background?
by moritz (Cardinal) on Apr 17, 2008 at 18:23 UTC
Re: How to run a process in background?
by kyle (Abbot) on Apr 17, 2008 at 18:28 UTC
Re: How to run a process in background?
by casiano (Pilgrim) on Apr 17, 2008 at 18:30 UTC
Re: How to run a process in background?
by mscharrer (Hermit) on Apr 17, 2008 at 19:59 UTC
    A simple:
    fork && exit;
    would do the trick. fork() generates a child process and returns 0 to it, but its PID to the parent process, so that the above line executes exit() in the parent - which is connected to the terminal - and doesn't executes it in the child process - which will then run in the background.