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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have a script that launches an application and then monitors to see if the application is has been closed. Here is a greatly simplified version:
use strict; my $pid = fork(); if (!$pid) { print "I am the child process\n"; system "emacs"; # this is just an example I am not really launching +emacs print "Child process should end now\n"; exit 0; } else { print "I am the parent of $pid\n"; while (kill 0,$pid) { print "My child is still alive\n"; sleep(3); # wait a little bit } print "Parent process done\n"; } __OUTPUT__ $ perl script.pl I am the child process I am the parent of 1324 My child is still alive My child is still alive My child is still alive Child process should end now My child is still alive My child is still alive etc.
The problem is that even after the child process is dead the parent process keeps going. According to the documentation for kill:

If SIGNAL is zero, no signal is sent to the process. This is a useful way to check that the process is alive and hasn't changed its UID. See perlport for notes on the portability of this construct.

So I thought "kill" would be a good way to see if the process was still going, but it doesn't appear to work. What am I missing? Is there a better way to do this?

In reply to Using 'kill' to see if a process is stil alive by fletcher_the_dog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found