I'm trying to write a perl script that forks off another program and monitors its execution during run time. Something
like the following snippet:
if ( ! defined($kidpid = fork() ) ) {
# fork returned undef, so failed
die "Cannot fork: $!";
} elsif ($pid == 0) {
# fork returned 0, so this branch is child
# want to tun program like this: ( time exe < stdin > stdout
+ ) >&! stdlog
exec( code to run program goes here.... );
# if exec fails, fall through to the next statement
die "can't exec date: $!";
} else {
# fork returned 0 nor undef so this branch is parent
# run-time monitoring code goes here....
waitpid($kidpid, 0);
}
I want to use a while(1) loop and wait for the child's pid, so I know when the executable's completed. Any idea on
how to do this? I'm able to run the executable in background (using a system call) but w/o run-time monitoring (don't
know child pid)?
Thanks.
E.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.