ps tip

I often use the ps -ef command when looking for a running process. However, sometimes I'm frustrated by the fact that ps truncates the the CMD output. As an example:

bleonard@opensolaris:~$ ps -ef | grep evolution-data
bleonard 15803     1   0   Sep 27 ?           0:00 /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-i

In a recent opensolaris-help forum post, Mike Meyer provided some undocumented BSD compatible options to get more details:

I habitually use "ps auxww" (note no "-" - bsd ps doesn't require it, and that triggers the BSD mode of /usr/bin/ps), which is all processes (ax) in a "user" (u) format. No w option truncates each line at 80 characters, one w option truncates each line at 132 characters, and two w options doesn't truncate it at all.

So, for my example:

bleonard@opensolaris:~$ ps auxww | grep evolution-data
bleonard 15803  0.0  0.22351610840 ?        S   Sep 27  0:00 /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2 --oaf-ior-fd=28

Of course, as it was also pointed out, once you know the process id you can get the same argument information, in a more readable format using, the pargs command:

bleonard@opensolaris:~$ pargs 15803
15803:	/usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-ii
argv[0]: /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24
argv[1]: --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2
argv[2]: --oaf-ior-fd=28

Or, in single line as pointed out in the comments below:

bleonard@opensolaris:~$ pgrep evolution-data | xargs pargs 
15803:	/usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-ii
argv[0]: /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24
argv[1]: --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2
argv[2]: --oaf-ior-fd=28
 
Comments:

Thanks, this is very useful! I was always bugged by OpenSolaris ps truncating commands, and couldn't figure out how to disable it.

Posted by Shmerl on September 29, 2010 at 01:30 PM GMT #

I do something similar almost every day:

pgrep pattern | xargs pargs | less

Posted by blah on September 30, 2010 at 03:42 AM GMT #

@blah, cool, thanks! I updated the entry with your tip.

Posted by W Brian Leonard on September 30, 2010 at 04:42 AM GMT #

Hi Brian,

A good tip, I'm using the pgrep/pargs combination a lot. If you replace "pargs" with "pfiles", you can also list all open files instead of arguments.

Cheers,
Andreas

Posted by Andreas on September 30, 2010 at 05:39 AM GMT #

Your happiness is premature :(

The only thing "ps XXX" does after detecting BSD mode - is just exec("/usr/ucb/ps",XXX). That is what you could always do by yourself.

The real pain of having two distinct ps (/usr/bin/ps and /usr/ucb/ps) is that - 1st one allows versatile filtering of rows and columns but always truncates output, the 2nd one doesn't truncate output but has very limited filtering capabilities.

When I 1st read Mike's post, I thought that he found a way to force /usr/bin/ps to NOT truncate output, but he didn't :(

Posted by Konstantin on November 02, 2010 at 07:04 AM GMT #

Well, the workaround is to enable suid, thus :
chmod 4555 /usr/ucb/sparc\*/ps

However : bear in mind that /usr/ucb/ps is no longer a privileged process; you can
only peek at your own processes. Since /usr/ucb/ps needed to read random
data from address spaces there was a risk of leakage and that is
compounded with the risk of /usr/ucb/ps being set-uid root, So, use it with caution, perhaps ok in development, but not so in production.

Posted by Subhash on January 07, 2011 at 08:15 AM GMT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

The Observatory is a blog for users of Oracle Solaris. Tune in here for tips, tricks and more as we explore the Solaris operating system from Oracle.

Connect with Oracle Solaris:


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today