Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > simple timer for win32, solaris and linux

Reply
Thread Tools

simple timer for win32, solaris and linux

 
 
elastic
Guest
Posts: n/a
 
      02-02-2004
I'm trying to implement a simple timer to work on win32 (98,2k,xp),
solaris and linux. where the last two are simple, the first seems to
be problematic.
the problem is that the kill command seems to always fail.
the pid is always negative and doesn't apear in the task manager.

this is the perl version I'm using :
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 635 provided by ActiveState Corp.
http://www.ActiveState.com
Built 15:34:21 Feb 4 2003
this is the function :
sub system_with_timeout {
my ($rc);
my ($command) = @_;

$pid = fork ();
if (! (defined ($pid))) { #hosed
die "fork() error: $!\n";
} elsif ($pid == 0) { #child
$rc = system ($command);
} else { #parent (defined $pid)
for ($i = 0 ; $i < $g_APP_RUN_TIMEOUT_SEC ; $i++) {
sleep 1;
if (kill 0, $pid) {
kill 9, $pid;
return -1;
}
}
}
return $rc;
}
if anyone has any idea of what I'm doing wrong here, please help.
 
Reply With Quote
 
 
 
 
elastic
Guest
Posts: n/a
 
      02-03-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (elastic) wrote in message news:<(E-Mail Removed). com>...
> I'm trying to implement a simple timer to work on win32 (98,2k,xp),
> solaris and linux. where the last two are simple, the first seems to
> be problematic.
> the problem is that the kill command seems to always fail.
> the pid is always negative and doesn't apear in the task manager.
>
> this is the perl version I'm using :
> This is perl, v5.6.1 built for MSWin32-x86-multi-thread
> (with 1 registered patch, see perl -V for more detail)
>
> Copyright 1987-2001, Larry Wall
>
> Binary build 635 provided by ActiveState Corp.
> http://www.ActiveState.com
> Built 15:34:21 Feb 4 2003
> this is the function :
> sub system_with_timeout {
> my ($rc);
> my ($command) = @_;
>
> $pid = fork ();
> if (! (defined ($pid))) { #hosed
> die "fork() error: $!\n";
> } elsif ($pid == 0) { #child
> $rc = system ($command);
> } else { #parent (defined $pid)
> for ($i = 0 ; $i < $g_APP_RUN_TIMEOUT_SEC ; $i++) {
> sleep 1;
> if (kill 0, $pid) {
> kill 9, $pid;
> return -1;
> }
> }
> }
> return $rc;
> }
> if anyone has any idea of what I'm doing wrong here, please help.


sorry, should be :
sub system_with_timeout {
my ($rc);
my ($pid);
my ($command) = @_;

$| = 1;
$pid = fork ();
if (! (defined ($pid))) { #hosed
die "fork() error: $!\n";
} elsif ($pid == 0) { #child
$rc = system ($command);
exit ($rc);
} else { #parent (defined $pid)
for ($i = 0 ; $i < $g_APP_RUN_TIMEOUT_SEC ; $i++) {
if (! (kill 0, $pid)) {
return $rc;
} else {
sleep 1;
}
}
print "timeout passed - killing : $pid\n";
kill 'KILL', $pid;
return -1;
}
return $rc;
}

problem is when the child is killed by initiating parent it doesn't
kill the process launched by the call to system.

still any help will be appreciated
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I know about the shutdown timer, is there a "switch on" timer... Mal Carter Computer Support 3 01-12-2008 01:58 AM
page timer, or redirect timer Simon ASP .Net 1 11-04-2005 07:14 PM
System.Timers.Timer/System.Threading.Timer Not Firing At All on Dev Server james.e.coleman@gmail.com ASP .Net 1 02-22-2005 09:41 PM
Cisco VPN Client Software for Solaris and Linux Thomas Cisco 1 04-08-2004 08:00 PM
System.Timers.Timer vs. System.Threading.Timer Kelsang Wangchuk ASP .Net 0 07-31-2003 04:28 PM



Advertisments