Section 3.3. Process Status: ps


3.3. Process Status: ps

The standard command to list process information is ps, process status. Solaris ships with two versions: /usr/bin/ps, which originated from SVR4; and /usr/ ucb/ps, originating from BSD. Sun has enhanced the SVR4 version since its inclusion with Solaris, in particular allowing users to select their own output fields.

3.3.1. /usr/bin/ps Command

The /usr/bin/ps command lists a line for each process.

$ ps -ef      UID   PID  PPID   C    STIME TTY         TIME CMD     root     0     0   0   Feb 08 ?           0:02 sched     root     1     0   0   Feb 08 ?           0:15 /sbin/init     root     2     0   0   Feb 08 ?           0:00 pageout     root     3     0   1   Feb 08 ?         163:12 fsflush   daemon   238     1   0   Feb 08 ?           0:00 /usr/lib/nfs/statd     root     7     1   0   Feb 08 ?           4:58 /lib/svc/bin/svc.startd     root     9     1   0   Feb 08 ?           1:35 /lib/svc/bin/svc.configd     root   131     1   0   Feb 08 ?           0:39 /usr/sbin/pfild   daemon   236     1   0   Feb 08 ?           0:11 /usr/lib/nfs/nfsmapid ... 


ps -ef prints every process (-e) with full details (-f).

The following fields are printed by ps -ef:

  • UID. The user name for the effective owner UID.

  • PID. Unique process ID for this process.

  • PPID. Parent process ID.

  • C. The man page reads "Processor utilization for scheduling (obsolete)." This value now is recent percent CPU for a thread from the process and is read from procfs as psinfo->pr_lwp->pr_cpu. If the process is single threaded, this value represents recent percent CPU for the entire process (as with pr_pctcpu; see Section 2.12.3). If the process is multithreaded, then the value is from a recently running thread (selected by prchoose() from uts/common/fs/proc/prsubr.c); in that case, it may be more useful to run ps with the -L option, to list all threads.

  • STIME. Start time for the process. This field can contain either one or two words, for example, 03:10:02 or Feb 15. This can annoy shell or Perl programmers who expect ps to produce a simple whitespace-delimited output. A fix is to use the -o stime option, which uses underscores instead of spaces, for example, Feb_15; or perhaps a better way is to write a C program and read the procfs structs directly.

  • TTY. The controlling terminal for the process. This value is retrieved from procfs as psinfo->pr_ttydev. If the process was not created from a terminal, such as with daemons, pr_ttydev is set to PRNODEV and the ps command prints "?". If pr_ttydev is set to a device that ps does not understand, ps prints "??". This can happen when pr_ttydev is a ptm device (pseudo tty-master), such as with dtterm console windows.

  • TIME. CPU-consumed time for the process. The units are in minutes and seconds of CPU runtime and originate from microstate accounting (user + system time). A large value here (more than several minutes) means either that the process has been running for a long time (check STIME) or that the process is hogging the CPU, possibly due to an application fault.

  • CMD. The command that created the process and arguments, up to a width of 80 characters. It is read from procfs as psinfo->pr_psargs, and the width is defined in /usr/include/sys/procfs.h as PRARGSZ. The full command line does still exist in memory; this is just the truncated view that procfs provides.

For reference, Table 3.2 lists useful options for /usr/bin/ps.

Table 3.2. Useful /usr/bin/ps Options

Option

Description

-c

Print scheduling class and priority.

-e

List every process.

-f

Print full details; this is a standard selection of columns.

-l

Print long details, a different selection of columns.

-L

Print details by lightweight process (LWP).

-o format

Customize output fields.

-p proclist

Only examine these PIDs.

-u uidlist

Only examine processes owned by these user names or UIDs.

-Z

Print zone name.


Many of these options are straightforward. Perhaps the most interesting is -o, with which you can customize the output by selecting which fields to print. A quick list of the selectable fields is printed as part of the usage message.

$ ps -o ps: option requires an argument -- o usage: ps [ -aAdeflcjLPyZ ] [ -o format ] [ -t termlist ]         [ -u userlist ] [ -U userlist ] [ -G grouplist ]         [ -p proclist ] [ -g pgrplist ] [ -s sidlist ] [ -z zonelist ]   'format' is one or more of:         user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid ctid         pri opri pcpu pmem vsz rss osz nice class time etime stime zone zoneid         f s c lwp nlwp psr tty addr wchan fname comm args projid project pset 


The following example demonstrates the use of -o to produce an output similar to /usr/ucb/ps aux, along with an extra field for the number of threads (NLWP).

$ ps -eo user,pid,pcpu,pmem,vsz,rss,tty,s,stime,time,nlwp,comm    USER  PID %CPU %MEM  VSZ  RSS TT      S    STIME        TIME NLWP COMMAND    root    0  0.0  0.0    0    0 ?       T   Feb_08       00:02    1 sched    root    1  0.0  0.1 2384  408 ?       S   Feb_08       00:15    1 /sbin/init    root    2  0.0  0.0    0    0 ?       S   Feb_08       00:00    1 pageout    root    3  0.4  0.0    0    0 ?       S   Feb_08    02:45:59    1 fsflush  daemon  238  0.0  0.0 2672    8 ?       S   Feb_08       00:00    1 /usr/lib/nfs/statd ... 


A brief description for each of the selectable fields is in the man page for ps. The following extra fields were selected in this example:

  • %CPU. Percentage of recent CPU usage. This is based on pr_pctcpu, See Section 2.12.3.

  • %MEM. Ratio of RSS over the total number of usable pages in the system (total_pages). Since RSS is an approximation that includes shared memory, this percentage is also an approximation and may overcount memory. It is possible for the %MEM column to sum to over 100%.

  • VSZ. Total virtual memory size for the mappings within the process, including all mapped files and devices, in kilobytes.

  • RSS. Approximation for the physical memory used by the process, in kilobytes. See Section 6.7.

  • S. State of the process: on a processor (O), on a run queue (R), sleeping (S), zombie (Z), or being traced (T).

  • NLWP. Number of lightweight processes associated with this process; since Solaris 9 this equals the number of user threads.

The -o option also allows the headers to be set (for example, -o user=USERNAME).

3.3.2. /usr/ucb/ps

This version of ps is often used with the following options.

$ /usr/ucb/ps aux USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND root         3  0.5  0.0    0    0 ?        S   Feb 08 166:25 fsflush root     15861  0.3  0.2 1352  920 pts/3    O 12:47:16  0:00 /usr/ucb/ps aux root     15862  0.2  0.2 1432 1048 pts/3    S 12:47:16  0:00 more root      5805  0.1  0.3 2992 1504 pts/3    S   Feb 16  0:03 bash root         7  0.0  0.5 7984 2472 ?        S   Feb 08  5:03 /lib/svc/bin/svc.s root       542  0.0  0.1 7328  176 ?        S   Feb 08  4:25 /usr/apache/bin/ht root         1  0.0  0.1 2384  408 ?        S   Feb 08  0:15 /sbin/init ... 


Here we listed all processes (a), printed user-focused output (u), and included processes with no controlling terminal (x). Many of the columns print the same details (and read the same procfs values) as discussed in Section 3.3.1. There are a few key differences in the way this ps behaves:

  • The output is sorted on %CPU, with the highest %CPU process at the top.

  • The COMMAND field is truncated so that the output fits in the terminal window. Using ps auxw prints a wider output, truncated to a maximum of 132 characters. Using ps auxww prints the full command-line arguments with no truncation (something that /usr/bin/ps cannot do). This is fetched, if permissions allow, from /proc/<pid>/as.

  • If the values in the columns are large enough they can collide. For example:

$ /usr/ucb/ps aux USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND user1     3132  5.2  4.33132422084 pts/4    S   Feb 16 132:26 Xvnc :1 -desktop X user1     3153  1.2  2.93544414648 ?        R   Feb 16 21:45 gnome-terminal --s user1    16865  1.0 10.87992055464 pts/18   S   Mar 02 42:46 /usr/sfw/bin/../li user1     3145  0.9  1.422216 7240 ?        S   Feb 16 17:37 metacity --sm-save user1     3143  0.5  0.3 7988 1568 ?        S   Feb 16 12:09 gnome-smproxy --sm user1     3159  0.4  1.425064 6996 ?        S   Feb 16 11:01 /usr/lib/wnck-appl ... 


This can make both reading and postprocessing the values quite difficult.




Solaris Performance and Tools(c) Dtrace and Mdb Techniques for Solaris 10 and Opensolaris
Solaris Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris
ISBN: 0131568191
EAN: 2147483647
Year: 2007
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net