Categories
Tech

Run child perl script in the background

I had a situation where a parent Perl script (web-accessible, in cgi-bin) needed to call a long-running child Perl script that was outside cgi-bin. I wanted the parent to call the child and then exit immediately, allowing the parent script browser window to stop loading and the child to continue running in the background and finish on its own.

What finally worked for me within the parent script was a system call utilizing a combination of piping the output to /dev/null and using the “background” command “&”:

system("/usr/bin/childscript.pl >/dev/null 2>&1 &");

This allows the parent to exit immediately (with “Done” in the browser window) while the child process finished in the background. Works on Ubuntu 7.10, at least.

One reply on “Run child perl script in the background”

Leave a Reply

Your email address will not be published. Required fields are marked *