Determine if a process was spawed by screen

Discussion in 'Perl Misc' started by Travis Spencer, Dec 28, 2003.

  1. Hello,

    I am trying to figure out if a process was spawned by screen
    (www.guckes.net/screen), in order to determine correctly if it is a runaway.

    I have come up with a subroutine, but it is slow and doesn't perform
    reliably. Can someone offer some suggestions that will speed it up and/or
    increase its accuracy?

    sub IsUsingScreen
    {
    my ($user, $pid) = @_;
    my @process = `ps -p $pid -o user,pid,ppid,comm`;

    # Calling `ps -p` returns two rows of output: a header row and the
    # row of data. To get the parent process's user, pid, etc., the
    # second row of output, $process[1], needs to be split on the
    # whitespace delimiter after all leading whitespace has been
    # trimmed off.
    $process[1] =~ s/^\s+//m;
    my ($p_user, $p_pid, $p_ppid, $p_comm) = split(/\s+/, $process[1]);

    if ($p_user eq $user)
    {
    &IsUsingScreen($user, $p_ppid);
    }
    else
    {
    return $p_comm =~ /screen/;
    }
    }

    Thanks.

    --

    Regards,

    Travis Spencer
    Portland, OR. USA
     
    Travis Spencer, Dec 28, 2003
    #1
    1. Advertising

  2. I guess I should have mentioned that my solution needs to run on Solaris 8+
    and Redhat 9.

    --

    Regards,

    Travis Spencer
    Portland, OR. USA
     
    Travis Spencer, Dec 28, 2003
    #2
    1. Advertising

  3. Travis Spencer

    Ben Morrow Guest

    "Travis Spencer" <> wrote:
    > I guess I should have mentioned that my solution needs to
    > run on Solaris 8+
    > and Redhat 9.


    Try using Proc::processTable form CPAN.

    Ben

    --
    If you put all the prophets, | You'd have so much more reason
    Mystics and saints | Than ever was born
    In one room together, | Out of all of the conflicts of time.
    |----------------+---------------| The Levellers, 'Believers'
     
    Ben Morrow, Dec 28, 2003
    #3
  4. Good suggestion, Ben. I have only installed a CPAN module once (in August).
    I can't remember exactly how I did it though. I didn't have root privileges
    then and I still don't :( If you have any suggestions that may jog my
    memory, I would appreciate it.

    --

    Regards,

    Travis Spencer
    Portland, OR. USA

    "Ben Morrow" <> wrote in message
    news:bsnbid$i45$...
    >
    > "Travis Spencer" <> wrote:
    > > I guess I should have mentioned that my solution needs to
    > > run on Solaris 8+
    > > and Redhat 9.

    >
    > Try using Proc::processTable form CPAN.
    >
    > Ben
    >
    > --
    > If you put all the prophets, | You'd have so much more reason
    > Mystics and saints | Than ever was born
    > In one room together, | Out of all of the conflicts of time.
    > |----------------+---------------| The Levellers,

    'Believers'
     
    Travis Spencer, Dec 29, 2003
    #4
  5. Sorry, Ben, disregard that last post. I can be a real lazy sod sometimes.
    I found the answers in the perlfaq and groups.google.

    Have a nice day.

    --

    Regards,

    Travis Spencer
    Portland, OR. USA

    "Ben Morrow" <> wrote in message
    news:bsnbid$i45$...
    >
    > "Travis Spencer" <> wrote:
    > > I guess I should have mentioned that my solution needs to
    > > run on Solaris 8+
    > > and Redhat 9.

    >
    > Try using Proc::processTable form CPAN.
    >
    > Ben
    >
    > --
    > If you put all the prophets, | You'd have so much more reason
    > Mystics and saints | Than ever was born
    > In one room together, | Out of all of the conflicts of time.
    > |----------------+---------------| The Levellers,

    'Believers'
     
    Travis Spencer, Dec 29, 2003
    #5
    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. Russell
    Replies:
    1
    Views:
    383
    Steve C. Orr [MVP, MCSD]
    Jan 21, 2004
  2. Pat
    Replies:
    5
    Views:
    558
  3. owl
    Replies:
    2
    Views:
    903
  4. Biranchi Narayan Panda
    Replies:
    1
    Views:
    2,837
    Alexey Smirnov
    Feb 17, 2010
  5. Peña, Botp
    Replies:
    1
    Views:
    261
    Robert Klemme
    Jan 24, 2004
Loading...

Share This Page