Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

running an external program without waiting for its execution

by rbi (Monk)
on Mar 02, 2001 at 14:33 UTC ( [id://61760]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,
I'm writing a CGI perl script driving a dynamic website where, among functionalities implemented, files can be uploaded to the server through the browser interface, and then I want to process these uploaded files.
Since this processing (either in perl or other language) takes long time I want to start the process and go on the with script, without waiting for the end of the file processing (I'm thinking to check in other ways the result of the processing, that anyway doesn't affect the following execution) and I don't want the file submitter to hang while waiting for this processing.
I saw that exec and system wait for the process completion. How can I do this?
Thank you very much in advance.
Roberto
  • Comment on running an external program without waiting for its execution

Replies are listed 'Best First'.
Re: running an external program without waiting for its execution
by arhuman (Vicar) on Mar 02, 2001 at 14:34 UTC

    Usually you would use fork and then use system, eval, exec, backquotes or other exotic ways.

    from fork node :
    unless ($pid = fork) { unless (fork) { exec "what you really wanna do"; die "no exec"; # ... or ... ## (some_perl_code_here) exit 0; } exit 0; } waitpid($pid,0);

    But in you case I wonder if it's the best way...

Re: running an external program without waiting for its execution
by merlyn (Sage) on Mar 02, 2001 at 19:33 UTC
Re: running an external program without waiting for its execution
by Ugly (Beadle) on Mar 02, 2001 at 20:40 UTC
    To carry on the theme of TMTOWTDI ...

    If you're running under Win32 (which you probably aren't) then one of the best ways of doing this kind of thing is to use the Win32::Process module. You can fire off a task as a DETACHED_PROCESS and then forget about it. Useful if you don't have a decent fork but not even remotely portable.
    --
    Ugly
    The early bird gets the worm, but the second mouse gets the cheese.

Re: running an external program without waiting for its execution
by telesto (Novice) on Mar 02, 2001 at 23:58 UTC
    If you're running in unix you could run it with the system command in the background with the "&".

    e.g.

    system("some command &");

    I do this to "parallelize" a bunch of running processes that I don't need to communicate with. You don't get the return value of "some command" but you if you don't care about the return value this should do the trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://61760]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-24 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found