simple timer for win32, solaris and linux

Discussion in 'Perl' started by elastic, Feb 2, 2004.

  1. elastic

    elastic Guest

    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.
    elastic, Feb 2, 2004
    #1
    1. Advertising

  2. elastic

    elastic Guest

    (elastic) wrote in message news:<>...
    > 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
    elastic, Feb 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    713
    Kelsang Wangchuk
    Jul 31, 2003
  2. Replies:
    1
    Views:
    1,598
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  3. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,199
    Bruce Barker
    Nov 4, 2005
  4. jose flanigan
    Replies:
    0
    Views:
    401
    jose flanigan
    Jul 3, 2003
  5. Replies:
    8
    Views:
    494
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page