tejnil has asked for the wisdom of the Perl Monks concerning the following question:
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.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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forked subprocess run-time monitoring
by belg4mit (Prior) on Apr 16, 2002 at 23:15 UTC |