4285ch02.fm Draft Document for Review May 4, 2007 11:35 am
44 Linux Performance and Tuning Guidelines
Example 2-3 Sample output of uptime
1:57am up 4 days 17:05, 2 users, load average: 0.00, 0.00, 0.00
2.3.4 ps and pstree
The ps and pstree commands are some of the most basic commands when it comes to
system analysis. ps can have 3 different types of command options, UNIX style, BSD style
and GNU style. Here we’ll take UNIX style options.
The ps command provides a list of existing processes. The top command shows the process
information as well, but ps will provide more detailed information. The number or processes
listed depends on the options used. A simple ps -A command lists all processes with their
respective process ID (PID) that can be crucial for further investigation. A PID number is
necessary to use tools such as pmap or renice.
On systems running Java™ applications, the output of a ps -A command might easily fill up
the display to the point where it is difficult to get a complete picture of all running processes.
In this case, the pstree command might come in handy as it displays the running processes
in a tree structure and consolidates spawned subprocesses (for example, Java threads). The
pstree command can be very helpful to identify originating processes. There is another ps
variant pgrep. It might be useful as well.
Example 2-4 A sample ps output
[root@bc1srv7 ~]# ps -A
PID TTY TIME CMD
1 ? 00:00:00 init
2 ? 00:00:00 migration/0
3 ? 00:00:00 ksoftirqd/0
2347 ? 00:00:00 sshd
2435 ? 00:00:00 sendmail
27397 ? 00:00:00 sshd
27402 pts/0 00:00:00 bash
27434 pts/0 00:00:00 ps
We will take some useful options for detailed information.
-e All processes. identical to -A
-l Show long format
-F Extra full mode
-H Forest
-L Show threads, possibly with LWP and NLWP columns
-m Show threads after processes
Here’s an example of the detailed output of the processes using following command:
ps -elFL
Example 2-5 An example of detailed output
[root@lnxsu3 ~]# ps -elFL
F S UID PID PPID LWP C NLWP PRI NI ADDR SZ WCHAN RSS PSR STIME TTY TIME CMD
4 S root 1 0 1 0 1 76 0 - 457 - 552 0 Mar08 ? 00:00:01 init [3]
1 S root 2 1 2 0 1 -40 - - 0 migrat 0 0 Mar08 ? 00:00:36 [migration/0]
1 S root 3 1 3 0 1 94 19 - 0 ksofti 0 0 Mar08 ? 00:00:00 [ksoftirqd/0]