Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How do I cleanly kill a spawned process on Win32.

by DrWhy (Chaplain)
on Feb 26, 2009 at 10:14 UTC ( [id://746507]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I cleanly kill a spawned process on Win32.
in thread How do I cleanly kill a spawned process on Win32.

Ha. That's exactly what I thought I saw from poking through Perl's source code. Is this documented anywhere?

FWIW, the server I'm testing already has a SetConsoleCtrlHandler defined, which is why I started this whole exercise in the first place.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on Re^2: How do I cleanly kill a spawned process on Win32.

Replies are listed 'Best First'.
Re^3: How do I cleanly kill a spawned process on Win32.
by BrowserUk (Patriarch) on Feb 26, 2009 at 10:50 UTC
      The kill method does not send signals on windows. See http://perldoc.perl.org/perlport.html. I spent a long time determining how to start a process on windows and then send a ctrl-c "signal". The secret is perl shares the console with the application that was started. Enjoy!
      #!/usr/bin/perl use strict; use warnings; use Win32; use Win32::Process; use Win32::Process 'STILL_ACTIVE'; use Win32::Process::Info qw{NT}; use Win32::Console; my $exe = $ARGV[0]; my $params = $ARGV[1]; my $appWorkingDir = $ARGV[2]; my $signalPollIntervalMillisec = $ARGV[3]; my $signalKillFile = $ARGV[4]; my $signalShutdownFile = $ARGV[5]; # Never die, only when child process terminates $SIG{INT} = 'IGNORE'; $SIG{TERM} = 'IGNORE'; my $ProcessObj; my $success = Win32::Process::Create($ProcessObj,$exe,$params,0,NORMAL +_PRIORITY_CLASS,$appWorkingDir); if ( $success ) { my $pid = $ProcessObj->GetProcessID(); while ( 'true' ) { $ProcessObj->Wait($signalPollIntervalMillisec); $ProcessObj->GetExitCode($exitcode); if ( $exitcode == STILL_ACTIVE ) { # Take action base on some flag if ( -e $signalKillFile ) { kill -9, $pid; exit -3; } elsif ( -e $signalShutdownFile ) { my $CONSOLE = Win32::Console->new(); $CONSOLE->GenerateCtrlEvent(CTRL_C_EVENT); } } else { # Process terminated on it's own exit $exitcode; } } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2025-03-27 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (70 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.