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
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