Checking on a Process
If a background process takes too long, or you change your mind and want to stop a process, you can check the status of the process and even cancel it.
ps
When you enter the command
ps
, you can see how long a process has been
running, the process ID of the background process, and the terminal
from which it was run. The tty
program shows the
name of the Terminal where it’s running; this is
especially helpful when you’re logged into multiple
terminals, as the following code shows:
$ ps
PID TT STAT TIME COMMAND
347 std S 0:00.17 -bash
391 p2 S+ 0:00.02 -bash
$ tty
/dev/ttyp1
std
corresponds to your current Terminal window,
and p2
corresponds to the Terminal window for
ttyp2
. In its basic form, ps
lists the following:
- Process ID (PID)
A unique number assigned by Unix to the process.
- Terminal name (TT)
The Unix name for the terminal from which the process was started.
- Runtime state (STAT)
The current state of each job.
S
is sleeping,R
is runnable,T
is stopped, andI
is idle (sleeping for more than 20-30 seconds). Additionally, the state can include+
to indicate it’s part of the foreground group process,E
to indicate the process is exiting, andW
to mean it’s swapped out.[5]- Runtime (TIME)
The amount of computer time (in minutes and seconds) that the process has used.
- COMMAND
The name of the process.
Each terminal window has its own terminal name. The previous code shows processes running on two windows: std and p2. If you want to see the processes that a certain user ...
Get Learning Unix for Mac OS X Panther now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.