Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: eval system timeout child process

by dasibre (Initiate)
on Sep 30, 2016 at 09:44 UTC ( [id://1172981]=note: print w/replies, xml ) Need Help??


in reply to Re: eval system timeout child process
in thread eval system timeout child process

thanks for your explanation andal. the current code doesn't get the child pid, thats one of the things i was trying to figure out how to do using system(). Most of the examples i've seen use fork+exec then kill the forked process. That doesn't work in my situation because it exec doesn't return to the program, unless theres an error according to perldocs.
  • Comment on Re^2: eval system timeout child process

Replies are listed 'Best First'.
Re^3: eval system timeout child process
by RonW (Parson) on Sep 30, 2016 at 18:07 UTC
    because it exec doesn't return to the program, unless theres an error

    That's because exec doesn't create a new process. It replaces the calling program with the specified program, running it in the same process.

    In Linux/Unix/POSIX based systems, the PID returned by fork to the parent is the child you wait for (or kill, if need be).

    my $pid = fork(); unless defined $pid { warn "Can't fork: $!\n"; ...; # do something else exit; } if ($pid == 0) { # child exec @cmd_and_parameters; die "Could not exec $cmd_and_parameters[0]: $!\n"; } else { # parent ...; # do other things waitpid($pid,0) == $pid or die "Error waiting for child: $!\n"; ...; # do more (if needed) }

    Using, for example, Parallel::ForkManager will make this easier, as well as hide any ugly details for OSs that do not have fork (like MS Windows).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172981]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-20 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found