Determine if a process was spawed by screen

T

Travis Spencer

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
 
T

Travis Spencer

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

--

Regards,

Travis Spencer
Portland, OR. USA
 
B

Ben Morrow

Travis Spencer said:
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
 
T

Travis Spencer

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 said:
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.
(e-mail address removed) |----------------+---------------| The Levellers,
'Believers'
 
T

Travis Spencer

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 said:
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.
(e-mail address removed) |----------------+---------------| The Levellers,
'Believers'
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top