Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Make perl script to wait while external process is finish

by wrongt (Initiate)
on Nov 17, 2011 at 07:46 UTC ( #938534=perlquestion: print w/ replies, xml ) Need Help??
wrongt has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I want that perl script while executing to wait for external java process to finish. Can anybody point me to the right place how can i do that? I try with function waitpid($pid,0); but this functions always return in $? = - 1 when i call it with existing process and nonexistent process pid.
Thanks in advance.

Comment on Make perl script to wait while external process is finish
Re: Make perl script to wait while external process is finish
by Anonymous Monk on Nov 17, 2011 at 09:21 UTC

    You use the system function, the default thing it does, is wait for the launched process to finish (assuming the process you launch, doesn't launch another and then finishes)

    Maybe even Proc::Background

Re: Make perl script to wait while external process is finish
by salva (Abbot) on Nov 17, 2011 at 09:28 UTC
    Has the java process been launched from the Perl script or externally? Because you can not wait using waitpid for a process that is not your child.

    If it is an external process, your best option will probably be to use some lock over a file that is also locked by the Java process (or a wrapper) while it runs.

    Alternatively, you can check if it is alive looking on the process table (see Proc::ProccessTable for instance) or if it runs as the same user as the Perl script with kill 0, $pid (see kill).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-12-28 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls