612 615




Linux Unleashed, Third Edition:Processes





-->















Previous
Table of Contents
Next




For the Superuser
When normal users issue the ps command, they see only their own processes. If you issue the ps command when you are logged in as the superuser (usually root, although you can change the name), you will see all the processes on the system because the root login owns everything running. This can produce very long outputs, especially on a system with several users, so you will probably want to pipe the output from the ps command to a page filter (such as more or less) or save the output in a file for further examination. Both commands are shown here:


ps | more
ps > /tmp/ps_file


Useful ps options
A useful ps option for checking user processes is -u, which adds several columns to the output of the ps command. The output from a user (not root) command using this option looks like this:


$ ps -u
USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND
bill 41 0.1 6.8 364 472 v01 S 23:19 0:01 -bash
bill 138 0.0 3.3 72 228 v01 R 23:34 0:00 ps -u


The most important addition to the output is the USER column, which shows who started and owns the process. The name listed under the USER column is the user’s login name, as found in the /etc/passwd file. (ps does a lookup in the /etc/passwd file to convert the user ID number—UID—to the proper username.)
This option also adds the column labeled %CPU which shows the percentage of CPU time that has been used by the process so far. The column %MEM shows the percentage of your system’s memory currently used by the process. These numbers can be handy for finding processes that consume far too much CPU or memory, called “CPU hogs” and “memory hogs” by most administrators. If you see a user process that has very high usage, it is worth checking to make sure it is a valid process and not a runaway that will continue to grind at your system’s resources.
When you issue this command logged in as root, you see all the processes running on the system. As before, you should consider paginating the output to make it readable. With some versions of Linux’s ps command, you can also use the -u option to specify a user’s processes by adding each username. For example, if you are logged in as root and want to see only Yvonne’s processes, you could issue the following command:


ps -u yvonne


This format of the -u option works with System V versions of ps, but not the BSD-based version of ps included with most Linux distributions (including the one of the CD-ROM). You can obtain other versions of ps on FTP and BBS sites. Most users can issue this command to examine other users’ processes, as well. This lets them find out who is hogging all the CPU time! It also lets the superuser see the processes that users are running when they report problems, without having to wade through all the system processes, as well.
Users can also see all the processes running on the system (instead of just the processes started by them) by using the -a option. Because the superuser sees all the processes on the system anyway, the root login doesn’t have to use this option, although it is still legal to use it. This output doesn’t change, though. When issued by a user (not root), the -a option produces the following output:


$ ps -a
PID TTY STAT TIME COMMAND
1 psf S 0:00 init
6 psf S 0:00 update (sync)
23 psf S 0:00 /usr/sbin/crond -l10
29 psf S 0:00 /usr/sbin/syslogd
31 psf S 0:00 /usr/sbin/klogd
33 psf S 0:00 /usr/sbin/lpd
40 psf S 0:00 selection -t ms
42 v02 S 0:01 -bash
43 v03 S 0:00 /sbin/agetty 38400 tty3
44 v04 S 0:00 /sbin/agetty 38400 tty4
45 v05 S 0:00 /sbin/agetty 38400 tty5
46 v06 S 0:00 /sbin/agetty 38400 tty6
41 v01 S 0:01 -bash
140 v01 R 0:00 ps -a


This is a relatively short output showing a very lightly loaded system. Most of the entries are the Linux operating system kernel and daemons, as well as serial port getty processes. Only the last two commands were started by the user who issued the ps command. Of course, you can’t tell who started each process with this output, so you can combine the -u and -a options (note that you use only one hyphen, followed by the option letters):


$ ps -au
USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND
root 64 0.0 1.5 41 224 v02 S 22:25 0:00 /sbin/agetty
38400 tty2
root 65 0.0 1.5 41 224 v03 S 22:25 0:00 /sbin/agetty
38400 tty3
root 66 0.0 1.5 41 224 v04 S 22:25 0:00 /sbin/agetty
38400 tty4
root 67 0.0 1.5 41 224 v05 S 22:25 0:00 /sbin/agetty
38400 tty5
root 68 0.0 1.5 41 224 v06 S 22:25 0:00 /sbin/agetty
38400 tty6
root 69 0.0 1.5 56 228 s00 S 22:25 0:00 gpm -t mman
root 71 0.3 3.6 388 532 pp0 S 22:26 0:02 -bash
root 155 0.0 1.5 77 220 pp0 R 22:37 0:00 ps -au
tparker 119 0.4 3.5 372 520 v01 S 22:32 0:01 -bash
tparker 132 0.1 2.2 189 324 v01 S 22:33 0:00 vi test


The -au options produce a list with all the same columns as the -u option but shows all the processes running on the system. The order in which you enter the options doesn’t matter, so -au is functionally the same as -ua. When you are adding several options, this can be handy.
A few other ps command line options are occasionally useful. The -l option adds information about which processes started each process (useful when you want to identify child processes):


$ ps -l
F UID PID PPID PRI NI SIZE RSS WCHAN STAT TTY TIME COMMAND
0 501 41 1 15 0 364 472 114d9c S v01 0:00 -bash
0 501 121 41 29 0 64 208 0 R v01 0:00 ps -l






Previous
Table of Contents
Next














Wyszukiwarka

Podobne podstrony:
615,19,artykul
615 618
Vzduchovka Slavia 612
612,17,artykul
Motyw ojczyzny w literaturze staropolskiej I literatury ~612
MAXa0 i 612
20081225190801id&615
609 612
611 612
Ch18 pg593 612
Dawn Stewardson Gone with the West (Har Sup Rom 615) (v1 0) (html)
612 (2)

więcej podobnych podstron