Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

waiting for process to finish

by ovedpo15 (Scribe)
on Jul 16, 2018 at 06:13 UTC ( #1218532=perlquestion: print w/replies, xml ) Need Help??

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

Hey guys.
Consider a function (lets call it A) which returns 1 if a process finished running, otherwise 0.
I would like to write another function which should wait until the process will finish running.
What's the best why to do it?

I thought of using the while loop and the wait(30); command.
Something like this:

until(A()) { sleep(30); }
I also can just call this subroutine until it will finish, although I don't think its smart because of all unnecessary junk.
What's the best way to do so?
I'm looking for the cleanest way to do it.

Replies are listed 'Best First'.
Re: waiting for process to finish
by Corion (Pope) on Jul 16, 2018 at 07:06 UTC

    Have you looked at wait? If you have the PID of the child process, you can wait for it to finish.

      The process is running on a different machine, so I can't use the wait operation.

        Maybe you can tell us a bit more about the framework you're using to launch processes at the remote end?

        If you don't want to poll, and can't use wait, maybe you can have the process at the remote end (or a wrapper around it) send you a message when it has finished?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2019-08-24 19:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found