473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

simple timer for win32, solaris and linux

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.
Jul 19 '05 #1
1 4313
el******@hotmail.com (elastic) wrote in message news:<4e**************************@posting.google. 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
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jose flanigan | last post by:
Does anybody have any code for python to read in Matlab *.mat version 5 files on a win32 machine and on Solaris? I found matfile (<ftp://ion.le.ac.uk/matfile/matfile.tar.gz>. ), which covers...
0
by: Brad Clements | last post by:
I need to get my cross platform medusa based package to support SSL on Windows and Linux. Using Python 2.3, there doesn't seem to be any way to do this on Windows without M2Crypto. Is that...
10
by: Markus Enders | last post by:
Hi everybody, currently we use DB2 7.1 on several Solaris machines. Now we are planning, to migrate to SUSE Linux (newest version). I wonder, if we can keep our DB2 version 7.1, or if we need to...
0
by: Zorba.GR | last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64 bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
2
by: Cam Chapman | last post by:
Does anyone have any experience migrating a DB2 database off UDB 6.1 (Solaris) to 7.2 (Linux)? The database does not already exist on the Linux box. Have created a DB2 instance fine. DB2...
17
by: Gaijinco | last post by:
How can I write a program to be executed for a given ammount of time. I mean I want to write a program that once started it doesn't do anything for like 2 minutes and then exits. It is...
19
by: UG | last post by:
I just wanted to know whether any timer facility exists in C, as it is not mentioned in K&R 2, or in the ISO Draft. By timer function i mean that when we use standard input function like scanf() or...
11
by: =?Utf-8?B?RXJpYw==?= | last post by:
I'm coming from Win32 world. Now, I'm porting the existing code to C#. I cannot find the equivalent Win32 Waitable Timer in C#. I have a thread to perform some task periodically like following: ...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.