system() not having command exit status

Discussion in 'Perl' started by Tim F., Jan 29, 2004.

  1. Tim F.

    Tim F. Guest

    Racked my brain and searched the archives but came up empty on both
    instances. :^()

    I have a script that is grabbing a pid out of a file and then using
    the exit status of `ps -p` to determine if the process is running. I
    don't have any of the Proc modules installed so this is the quickest
    way I could come up with. The problem is that system("ps -p $pid") ==
    0 is always true. I can run the command at the unix shell and it
    comes back with $? == 1.

    My next step is to just create a hash of all the running pids and test
    against that. Thanks for the help.

    Tim

    Code Snippit
    foreach $Username (@master_list) {
    if (-e "/home/$Username/dynamo/home/servers/$Username/logs/dynamo.pid")
    {
    $fh->open("< /home/$Username/dynamo/home/servers/$Username/logs/dynamo.pid")
    ;
    $pid = <$fh>;
    }else{
    next
    }
    $ENV{DYNAMO_HOME} = "/home/$Username/dynamo/home";

    # Now we check to see if that PID is a valid process and if so issue
    the
    # stopDynamo command for that particular users instance;

    $cmd = "ps -p $pid >/dev/null";
    $kill_cmd = "/home/$Username/dynamo/home/bin/stopDynamo $Username
    -kill";
    #system($cmd) == 0 and system($kill_cmd);
    print system($cmd),"\n";
    } # End foreach
    Tim F., Jan 29, 2004
    #1
    1. Advertising

  2. Tim F.

    Joe Smith Guest

    Tim F. wrote:

    > I have a script that is grabbing a pid out of a file and then using
    > the exit status of `ps -p` to determine if the process is running. I
    > don't have any of the Proc modules installed so this is the quickest
    > way I could come up with.


    perldoc -f kill ;# Look for the paragraph with "zero"
    -Joe
    --
    I love my TiVo - http://www.inwap.com/u/joe/tivo/
    Joe Smith, Jan 29, 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. Sami Viitanen

    command exit status on windows

    Sami Viitanen, Sep 24, 2003, in forum: Python
    Replies:
    1
    Views:
    537
    Felix McAllister
    Sep 24, 2003
  2. oscartheduck

    capturing system exit status

    oscartheduck, Apr 2, 2007, in forum: Python
    Replies:
    1
    Views:
    367
    Michael Hoffman
    Apr 2, 2007
  3. jacob navia
    Replies:
    3
    Views:
    550
    Nick Keighley
    Feb 24, 2010
  4. Keith Thompson
    Replies:
    10
    Views:
    685
    Tim Rentsch
    Mar 3, 2010
  5. kaleem
    Replies:
    8
    Views:
    799
    Tad McClellan
    Dec 14, 2006
Loading...

Share This Page