An update: I need to run a couple processes (or threads) in parallel, and when one of them ends (which one ends first will vary), kill the other and continue the main program. I was hoping to use a signal handler to catch a SIGCHLD to notify me when the first child ends so I don't have to keep polling them both. But since the forked child in Perl on Windows apparently does not send a SIGCHLD when it ends, that method seems to be out.
If I use Win32::Process to create the children, I can't use Wait(). Wait() blocks, so I can only wait for one of the children and I don't know which one to wait for. So I think the only option left is to loop and check for the continued existence of each process every second or so. I don't think that should take too much CPU time (any experience with that?), but it's clearly not as elegant as simply waiting for notification by the OS via a signal when the child dies. Garyl > I've never used fork - being exclusively a Windows boy it's not > something I ever got familiar with :) > > I have had some success spawning child processes and killing them, even > passing in ctrl C to the console group, which is trickier. Have you > tried getting parent and child to print their pid after forking? Maybe > even get both to sleep for 30 secs and check the process table? > > P. > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: 02 March 2005 07:39 > To: Paul Sobey > Subject: RE: Win32::Process->kill() macro not defined > > Your script worked on mine too, so I started substituting parts of my > script into yours bit-by-bit -- they were really quite similar. Turns > out I had a typo -- kill() instead of Kill(). Strange error message > though. > > I've also been experimenting with fork and wait/waitpid as another > option. Whenever I try to use kill 'HUP', $Pid (or other signal) to kill > a child process though, I kill the main program. I'm wondering if it's > because the PIDs returned under Windoze are negative and using negative > PIDs is supposed to kill the whole process group. Or maybe because there > really isn't a separate process to kill under windows -- I think I read > it's actually implemented as a thread. Can you confirm? I also don't > seem to be able to detect a CHLD signal when the child exits. > > Thanks for the reply. > > Garyl > > > > This works perfectly on my system (XP Pro SP2, 5.8.6) - starts and kills > > the ping process. The sleeps are so you can watch with task > > manager/pslist. Can you confirm whether it works on yours? > > > > Paul > > > > > > use Win32::Process; > > > > my $ProcessObj; > > Win32::Process::Create($ProcessObj, > > "$ENV{SYSTEMROOT}\\System32\\ping.exe", > > "ping -t 127.0.0.1", > > 0, > > NORMAL_PRIORITY_CLASS, > > ".") || die; > > > > my $pid = $ProcessObj->GetProcessID(); > > > > print "Got pid $pid\n"; > > sleep 5; > > $ProcessObj->Kill(0); > > print "Process killed\n"; > > sleep 5; > > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of > > [EMAIL PROTECTED] > > Sent: 25 February 2005 08:43 > > To: perl-win32-users@listserv.ActiveState.com > > Subject: Win32::Process->kill() macro not defined > > > > I'm trying to use Win32::Process to run an external program > > asynchronously while I run a countdown timer in the main program. If the > > timer runs out, I want to kill the other program/process. I am able to > > create the second process fine, my program continues to the timer, but > > when the timer expires and the program tries to execute: > > $ChilcProcObj->Kill(0); # or 1 or -1 > > I get a message: Your vendor has not defined Win32::Process macro kill, > > used at TestFork3.pl line 51. at C:/Perl/site/lib/Win32/Process.pm line > > 47. I don't know anything about the internals of this module -- was > > something not compiled in? > > > > This happens regardless of whether the second process is still running > > when the timer expires, or if it ended on its own earlier. > > > > I found a posting in another forum where someone ran into the same > > problem, but got no helpful responses. I'm using perl v5.8.3 built for > > MSWin32-x86-multi-thread. > > > > Is this a problem fixed in a later version perhaps? I was going to try a > > later version, but the ActiveState download site wasn't working. (It > > returns "Script failed to send data.") > > > > Thanks, > > Garyl Erickson _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs