Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: eval system timeout child process

by RonW (Parson)
on Sep 30, 2016 at 18:07 UTC ( [id://1173021]=note: print w/replies, xml ) Need Help??


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

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://1173021]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found