DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the UNIX system shell

Obtaining the status of running processes

The ps command gives you the status of all the processes currently being run. For example, you can use the ps command to show the status of all the processes you run in the background mode using ``&'' (described in ``Special characters'').

The next section, ``Terminating active processes'', discusses how you can use the PID (process identification) number to stop a command from executing. A PID is a unique number that the UNIX system assigns to each active process.

In the following example, grep is run in the background, and then the ps command is issued. The system responds with the process identification (PID) and the terminal identification (TTY) number. It also gives the cumulative execution time for each process (TIME), and the name of the command that is being executed (COMMAND).

   $ grep word * > temp &
   28223
   $ ps
   PID	TTY	TIME   COMMAND
   28124	tty10	0:00   sh
   28223	tty10	0:04   grep
   28224	tty10	0:04   ps
   $
Notice that the system reports a PID number for the grep command, as well as for the other processes that are running: the ps command itself, and the sh (shell) command that runs throughout the time you are logged in. (The shell program sh interprets--that is, passes on to the computer--shell commands.)

See the ps (1) manual page for all available options and an explanation of the capabilities of each.

You can suspend and restart programs if your login has been configured for job control. See your system administrator to have your login set up to include job control. The jobs command also gives you a listing of current background processes, running or stopped. However, in addition to the PID, the jobs command gives you a number called the ``job identifier'' (JID) and the original command typed to initiate the job (job_name). You need to know the JID of a process whenever you want to restart a stopped job or resume a background process in foreground. The JID is printed on the screen when you enter a command to start or stop a process. To obtain information about your stopped or background jobs, type:

   jobs
The system will respond by displaying information such as the following:

[JID] - Stopped(signal) job_name

or

[JID] + Running job_name


Next topic: Terminating active processes
Previous topic: Executing processes at regular intervals

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004