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 any COM S Linux/UNIX machine and type man command.
Process Listing
The ps command lists processes that are running under your current login:
UNIX> ps
PID TTY TIME CMD
14191 pts/6 0:01 bash
15170 pts/6 0:00 vi
In the above example, the user is running a shell (bash) and also the vi editor. Note that these are only the processes for the current shell. To see a more complete list of processes you are running, run the following command (where username is your ISU username):
UNIX> 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 are some useful keyboard shortcuts:
Shortcut | Signal | Description |
---|---|---|
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 | SIGSTP | 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. |
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:
UNIX> 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:
UNIX> 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 tot he foreground, use the fg command. If you suspend a process by pressing Ctrl-Z, you may return to it by running fg. To control a process that has already been suspended, use the bg command. This command allows the current process to continue running in the background. Both of these commands also accept the PID of a process as an argument. You can consult the manual pages for fg and bg for more information.