ps doesnt show all processes

480 views
Skip to first unread message

Matthias Teege

unread,
Apr 25, 2015, 3:26:03 PM4/25/15
to rex-...@googlegroups.com
Hi,

ps doesn't show any commands with arguments if more then one parameter
is used.

use strict;
use warnings;

use Rex -feature => ['1.0'];
use Data::Dumper;

task "get_procs", sub {
my @list;

@list = grep { $_->{"command"} =~ /mksh|perldoc/ } ps("command");
print Dumper(\@list);

@list = grep { $_->{"command"} =~ /mksh|perldoc/ } ps("command", "user");
print Dumper(\@list);
};

% rex -v
(R)?ex 1.1.0

% rex -f t.rex get_procs
[2015-04-25 13:11:27] INFO - Running task get_procs on <local>
$VAR1 = [
{
'command' => 'mksh'
},
{
'command' => '/usr/bin/perl /usr/bin/perldoc Rex::Commands::Process'
}
];
$VAR1 = [
{
'user' => 'm',
'command' => 'mksh'
}
];
%

Thanks
Matthias

Ferenc Erki

unread,
Apr 26, 2015, 11:09:37 AM4/26/15
to rex-...@googlegroups.com, matthi...@mteege.de
hi Matthias,

TL;DR version: pass the `command` argument as the last one.

Long version:

Rex uses the `ps` commands to gather the process information. As far as I know there's no machine readable output for that command. So Rex currently tries to do it on it own, by splitting the resulting lines on whitespaces (`/\s+/`) to extract the differen fields, while keeping the number of extracted fields to the number of expected fields.

Since the command field of the output itself can contain spaces (e.g. `/usr/bin/perl /usr/bin/perldoc Rex::Commands::Process`), this method only can work if `ps` is asked to output the command field as the last one in the line (so it is prevented from being split on whitespaces as the maximum allowed number of splits already happened).

I'm also going to open an issue about that on github, so we might come up with another method to collect process information, or at least ensure that if `command` fields is requested, it is used as last.

cheers,
FErki
Reply all
Reply to author
Forward
Message has been deleted
0 new messages