-->
Previous | Table of Contents | Next |
The ps listing displays four default headings as indicators of the information in the fields below each heading: PID, TTY, TIME, and COMMAND. Table 19.6 explains these headings.
Field | Explanation |
---|---|
PID | The process identification number |
TTY | The terminal on which the process originated |
TIME | The cumulative execution time for the process, in minutes and seconds |
COMMAND | The name of the command being executed |
Suppose that you want to sort a file named sales.dat, save a copy of the sorted file in a file named sales.srt, and mail the sorted file to the user sarah. If you also want to put this job in the background, enter the following command:
sort sales.dat | tee sales.srt | mailx -sSorted Sales Data sarah &
To monitor this process, enter ps to see a display such as this one:
PID TTY TIME COMMAND 16490 tty02 0:15 sort 16489 tty02 0:00 mailx 16492 tty02 0:00 ps 16478 tty02 0:00 bash 16491 tty02 0:06 tee 16480 tty02 96:45 cruncher
You see the accumulated time and PID for each process started with the command. You also see information for your login shell (bash) and for ps itself. Notice that all the commands in the pipe are running at once, just as you would expect (this is the way the piping process works). The last entry is for a command that has been running for more than an hour and a half. If thats a problem, you may want to terminate the process by using the kill command (described later in this chapter). If you enter ps and see only the following listing, the previous job you put into the background is complete:
PID TTY TIME COMMAND 16492 tty02 0:00 ps 16478 tty02 0:00 bash 16480 tty02 99:45 cruncher
NOTE: Use ps occasionally to check the status of a command. If, however, you use ps every second while waiting to see whether the background job is complete, putting the job in the background doesnt make much sense in the first place.
Obtaining More Information About Processes with ps
Sometimes you need to know more about your processes than what the default ps listing provides. To generate additional information, you can invoke some of the flags listed in Table 19.7.
Flag | Description |
---|---|
-a | Shows processes of other users also. |
-c | Displays command name from task_struct environment. |
-e | Shows environment after command line and and. |
-f | Shows forest family tree format (processes and subprocesses). |
-h | No header. |
-j | Jobs format. |
-l | Long format. |
-m | Displays memory info. |
-n | Numeric output for USER and WCHAN. WCHAN is the name of the kernel function where the process is sleeping, with the sys_ stripped from the function name. If /etc/psdatabase doesnt exist, the number is hexadecimal instead. |
-r | Running processes only. |
-s | Signal format. |
-S | Adds child CPU time and page faults. |
-txx | Processes associated with ttyxx only. |
-u | User format; gives user name and start time. |
-v | vm (virtual memory) format. |
-w | Wide output; doesnt truncate command lines to fit on one line. |
-x | Shows processes without controlling terminal. |
The ps command gives only an approximate picture of process status because things can and do change while the ps command is running. The ps command gives a snapshot of the process status at the instant ps executed. The snapshot includes the ps command itself.
The following examples show three commands. The first command is the login shell (bash). The second command is sort, which is used to sort the file named inventory. The third command is the ps command youre now running.
To find out what processes youre now running, use the following command:
$ ps PID TTY TIME COMMAND 65 tty01 0:07 -bash 71 tty01 0:14 sort inventory 231 tty01 0:09 ps
To obtain a full listing, use this command:
$ ps -uax UID PID PPID C STIME TTY TIME COMD amanda 65 1 0 11:40:11 tty01 0:06 -bash amanda 71 65 61 11:42:01 tty01 0:14 sort inventory amanda 231 65 80 11:46:02 tty01 0:00 ps -f
Notice a few things about this full listing. In addition to the PID, the PPID is listed. The PPID is the process ID number of that processs parent process. In this example, the first process listed, PID 65, is the parent of the following two. The entry in the fourth column (the column headed C) gives the amount of CPU time a process has used recently. In selecting the next process to work with, the operating system chooses a process with a low C value over one with a higher value. The entry in the STIME column is the time at which the process started.
To monitor every process on the system and get a full listing, enter ps -uax. By piping the command through the grep $LOGNAME command, the processes belonging to your login name are displayed while all others are filtered out. To see a full listing of all your processes, enter this:
ps -uax | grep $LOGNAME
To list processes for two terminals (for example, tty1 and tty2), use the following command:
$ ps -t 1 2 PID TTY TIME COMMAND 32 tty01 0:05 bash 36 tty02 0:09 bash 235 tty02 0:16 vi calendar
Previous | Table of Contents | Next |