simple timer for win32, solaris and linux

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elastic

    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.
    ActiveState enables DevOps, InfoSec, and Development teams to improve their security posture while simultaneously increasing productivity and innovation to deliver secure applications faster.

    Built 15:34:21 Feb 4 2003
    this is the function :
    sub system_with_tim eout {
    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_TIME OUT_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.
  • elastic

    #2
    Re: simple timer for win32, solaris and linux

    elastic_@hotmai l.com (elastic) wrote in message news:<4e49c501. 0402012313.4c17 b893@posting.go ogle.com>...[color=blue]
    > 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_tim eout {
    > 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_TIME OUT_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.[/color]

    sorry, should be :
    sub system_with_tim eout {
    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_TIME OUT_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

    Comment

    Working...