Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Terminate process tree in windows

by sjwnih111 (Novice)
on Oct 30, 2013 at 18:36 UTC ( #1060411=perlquestion: print w/replies, xml ) Need Help??
sjwnih111 has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone, I'm using the following to call a child process from my script and then time it out:
my $pid = fork(); if (!$pid) { system($command); } else { sleep $max_time; print "Since $max_time minutes have elapsed, w +ill kill process with PID $$ "; system("TASKKILL /F /T /PID $$"); }
Two problems, and I'm not sure what they're from. (1) After completing the child process on time, I get a popup from windows that says "perl.exe has stopped working..." (2) When I look in task manager, there are a bunch of Taskill.exe that seem to be left over even after I have closed the processes they were trying to kill... If anyone has any idea what's going on it would be very helpful.

Replies are listed 'Best First'.
Re: Terminate process tree in windows
by Corion (Pope) on Oct 30, 2013 at 19:24 UTC

    While fork() does kinda work on Perl on Windows, it is only emulated by Perl. Windows only ever sees one Perl process, no matter how much you fork() from it. When you use taskkill, you kill off the one Perl process.

    In my experience, it's best not to use fork() on Windows and use threads or plain subprocesses instead. This usually requires a different approach in the program though.

Re: Terminate process tree in windows
by bojinlund (Parson) on Oct 31, 2013 at 06:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1060411]
Approved by Old_Gray_Bear
help
Chatterbox?
[ambrus]: I don't much like highlighting matching parenthesis, because I've had some bad experiences with distracting implementations of that.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-02-27 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.