in reply to kill a process with process name

I tried Win32::Proc but the obj handle was not visible to the parent

This works for me:
use warnings; use strict; use Win32::Process; my $ProcessObj; Win32::Process::Create ( $ProcessObj, # Process handle "C:\\Perl\\bin\\perl.exe", "C:\\Perl\\bin\\perl.exe gash1.pl", 0, # inherit handles boolean NORMAL_PRIORITY_CLASS, # Creation flags "."); my $pid = $ProcessObj->GetProcessID(); my $exitcode = 37; print "Hit <RETURN> to continue...."; <STDIN>; Win32::Process::KillProcess($pid, $exitcode);
gash1.pl:
use warnings; use strict; while (1) { print "$0 in a loop....\n"; sleep 1; }
I had a similar requirement a while ago, Proc::Background does a similar thing, but I also had to use standard modules. I have put my code on my scratchpad - feel free to use any bits you like.

Replies are listed 'Best First'.
Re^2: kill a process with process name
by Anonymous Monk on Apr 14, 2010 at 09:00 UTC
    thanks but I'm using fork hence the handle is not visible to the parent process.