Department of Electrical Engineering and Computer Science



Process-related commands

A process is a program that is currently being executed on the machine. This document describes how to list running processes, send signals to the current process, terminate processes, and manage foreground and background processes. For additional information about any of these commands, log onto an EECS machine and type man command.

Process listing

The ps command lists processes that are running under your current login:

prompt> ps
  PID TTY TIME CMD
14191 pts/6 0:01 zsh
15170 pts/6 0:00 vi

In the above example, the user is running a shell (zsh) and also the vi editor. Note that these are only the processes for the current login. To see a more complete list of processes you are running, run the following command (where username is your login name):

ps aux | grep username

Signals

Signals are requests sent to processes to control their behavior. You can use certain keyboard shortcuts to send a signal to a process, or you can use the kill command discussed later in this document. Here is are some useful keyboard shortcuts:

Keyboard ShortcutSignalDescription
Ctrl-C SIGINT This sends an interrupt request to the current process, which typically terminates the process immediately. Use this if you want to halt the program you are running. This can be especially useful if the program is engaged in an infinite loop.
Ctrl-Z SIGTSTP This sends a request to temporarily stop the current process. For example, if you are in the vi editor, pressing Ctrl-Z will stop vi and return you to the command line. You can then use the fg command to return to vi. (The fg command is discussed later in this document.)

Termination

The kill command can be used to terminate a process. kill takes the process ID (PID) of the process you want to terminate as an argument. The PID can be obtained using the ps command. Here is an example:

prompt> ps
  PID TTY TIME CMD
14191 pts/6 0:01 zsh
15170 pts/6 0:00 vi

Suppose you want to terminate vi. From the output above, the PID for vi is 15170. Next, use kill to terminate the process:

kill 15170

Foreground and background processes

A foreground process is the active process running in your shell. A background process is a process that has been suspended using Ctrl-Z (or the SIGSTP signal).

To bring a process to the foreground, use the fg command. If you suspend a process by pressing Ctrl-Z, you may return to it by running fg.

The bg command can be used to control a process that has been suspended. Running bg will allow the process to continue running in the background. Both fg and bg also accept the PID of a process as an argument. Consult the manual pages for fg and bg for more information.


 

The University of Tennessee, Knoxville. Big Orange. Big Ideas.

Knoxville, Tennessee 37996 | 865-974-1000
The flagship campus of the University of Tennessee System