in reply to command execution & timeout in windows
The problem you are having is that you are trying to use Win32::Process::KillProcess() on a $pid returned by fork.
Under AS 5.6.1, fork is a simulation of the unix fork, and it is done using native threads, not processes. This can be confirmed by printing out the $pid returned by fork. On my system they always come back as a negative number but process ids are always positive. You can also see the second thread come into existance, and disappear if you watch the Task Manager.
To kill the forked 'process', just use the standard perl kill function. kill 9, $pid;.
#! perl -slw use strict; use Config; use Win32::Event; use Win32::Process; $|++; #print $Config{sig_name}; my $event = Win32::Event->new(1, 0, 'test'); if (not defined(my $pid = fork())) { warn "can not fork: $!\n"; return; } elsif ($pid) { print "Parent processid: $$; child:$pid"; if($event->wait( 5000 )) { print 'The child signalled and terminated'; } else { print 'Parent: child continuing after 5 secs'; if($event->wait( 5000 )) { print 'The child signalled and terminated'; } else { print 'Parent: child still continuing after 10 secs'; my $exitCode = 0; print "Parent: Attempting to kill processid $pid"; # Win32::Process::KillProcess( $pid, $exitCode ) or warn $^ +E; # print "Parent: KillProcess returned: $exitCode"; kill 9, $pid or die $!; print "Parent: KillProcess returned: $?"; } } print "Parent dying"; } else { for (1..20) { print "Child process: $$"; sleep 1; } print "Child: signalling parent"; $event->set; print "Child dying"; exit 12345; } __END__
Output
C:\test>217881 Parent processid: 273; child:-295 Child process: -295 Child process: -295 Child process: -295 Child process: -295 Child process: -295 Parent: child continuing after 5 secs Child process: -295 Child process: -295 Child process: -295 Child process: -295 Child process: -295 Parent: child still continuing after 10 secs Parent: Attempting to kill processid -295 Parent: KillProcess returned: 0 Parent dying C:\test>
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: command execution & timeout in windows
by Anonymous Monk on Dec 05, 2002 at 23:03 UTC | |
by BrowserUk (Patriarch) on Dec 06, 2002 at 00:04 UTC |