delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/05/10/04:42:09

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <55E0A3E94323974F83CFC5AAB96F68B801418A0B@snnexc03.in.ce.com.au>
From: Sonam Chauhan <sonam DOT chauhan AT ce DOT com DOT au>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: problems in Perl process management
Date: Tue, 10 May 2005 18:41:27 +1000
MIME-Version: 1.0
X-IsSubscribed: yes
Note-from-DJ: This may be spam

------_=_NextPart_000_01C5553C.0E3A55F0
Content-Type: text/plain

Hello - 

I'd appreciate help with problems doing process management in Cygwin/Perl. 

I have a Perl application that creates child processes - I need it to kill
processes that exceed a certain timeout. I am trying to use the
Proc::ProcessTable and Proc::Killfam CPAN modules for this.

I ran into two problems: 

The first problem was a "can't stat /dev" error message produced when
calling Proc::Killfam. This problem was fixed by a script I found that
populated entries under /dev. 

To understand the next probem, have a look at the simple test script
attached. The script forks a child process, which runs `sleep` in a third
process. The parent process then tries to kill both children on expiry of a
timeout. The script behaves perfectly on Linux -- it works as expected and
kills the fork-ed child Perl process, as well it's `sleep` child process.
However, on Cygwin/Perl it only kills the fork-ed Perl child - it cannot
kill the `sleep`-ing child. 

The problem seems to be that the process table data returned by
Proc::ProcessTable seems to differ from the data returned 'ps'.
Specifically, Proc::ProcessTable returns the WINPID of a process as the PID
for the backticked `sleep` process. 

The closest issue I found in the list archives is this one: 
        http://sourceware.org/ml/cygwin/2005-02/msg00224.html 
It does not seem to have been resolved. 

I'm running Perl on Cygwin on Windows XP SP2. Running 'cygcheck -c' gives
the following package status for cygwin and Perl:
--------------------------
cygwin  1.5.16-1   OK
perl    5.8.6-4    OK
--------------------------

Can anyone help?

Regards,
Sonam Chauhan
-- 
Electronic Commerce, Corporate Express Australia Ltd.
Phone: +61-2-9335-0725, Email: sonam DOT chauhan AT ce DOT com DOT au
 



------_=_NextPart_000_01C5553C.0E3A55F0
Content-Type: application/octet-stream;
	name="timeout_test2.pl"
Content-Disposition: attachment;
	filename="timeout_test2.pl"

#!/usr/bin/perl 
use Proc::Killfam;

#Alarm Signal Handler - kills all children subprocesses
$SIG{ALRM} = sub {
	print "$$: woke up after $timeout sec. Killing child family: $childpid\n";  
	# This kills all children processes 
	killfam 'KILL', $childpid; 
	# However, on Perl/Cygwin, the backticked `sleep` process is not killed
}; 

# Main routine - sets alarm and forks child to start a blocking `sleep`
sub timeout_test {
	print "Starting... my own PID=$$\n";
	$timeout =3;
	$childpid = fork();
	if ($childpid > 0) { # this is the parent process - wait for children to die
		print "$$: Forked child $childpid. Set alarm for $timeout seconds\n";
		alarm $timeout;
		do {
			$kid = waitpid (-1, 0);
		} until $kid == -1;
		exit;
	}
	$s = `/bin/sleep 7`;
	print "Sleep ended";
}

# Kick it all off 
timeout_test();




------_=_NextPart_000_01C5553C.0E3A55F0
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------_=_NextPart_000_01C5553C.0E3A55F0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019