Commands covered in this section: ps wait sleep fg bg nohup kill
When using UNIX, process management becomes very important, because a
given program can start more than one process and you can have
suspended processes, processes running in the background, ...
In this section we will show you how to see what processes you are
running, how to run a process in the background and how to bring them to
Viewing Running processes
Use ps to view what processes are running, this will give you the
| PID || TTY || TIME || COMMAND |
| 067 || console || 00:05 || sh |
| 063 || tty02 || 10:20 || /bin/local/usr/zsh|
| 062 || tty02 || 10:22 || ps|
| 060 || tty00 || 12:05 || /net/pppd|
This tells you what the Process Id of the given process is, where it is
being run, at what time it started, and what command is being
To get more details use ps -f, this will give you the userid which
started the process, the parent process which spun the child process,
and a few more ... There is also the ps -l option which is an extended
version of the output ps provides, all the extra information given with
the -l option is really of use just for system admins, you can have a go
at it but it won't be of much use.
Further useful options ps offers are also available threw the command
line options of ps. Use
ps -e to get details about every process
running, ps - u userlist gives details about all the processes
run by the given user. Use ps -t ttynn gives details about all
processes run on the given device, you can replace ttynn by any
valid device listed in the /dev directory.
To suspend the execution of a process to a later time use sleep
time replacing time with the time in seconds to wait
before executing the process.
To run a process after another process use wait PID where
PID is the process Id to wait for. After that process is executed
the specified process will run. If you do not give a PID your process
will wait for all other background processes to finish executing
Background & Foreground Processes
To run a process in the background use bg commands, where
commands is what you want your shell to execute. Only non-
interactive processes can run in the background and interactive process
will be just suspended.
To bring a process to the foreground use fg process, the process
will then run in the foreground. You can use fg to bring to the
foreground any suspended process or any process running in the
Background Processes (Advanced Use)
At certain time the need to leave a process running when you log off. To do this the nohup
command is availabe. This will in effect start the process and let you log off ignorinag any hangup signals.
Use nohup command args... &, this will start the command you specify and pass arguments to it (if any) leaving
the command to execute when you log off. The & sign is required because the nohup command will not cause the process to run in the backgound
automatically, so the & is used to start running the process.
It might, at some point, become necessary to kill/terminate a process. This is most commonly used to
terminate a process which is no longer responding, or to kill all processes before logging out. Leaving running processes
which are practically useless will slow down your system, so make sure no processes are left running. This is just a case of
cleaning up after use type of situation.
Use kill -s SIGNAL PID to send a signal to the given PID.
If you do not know which signal to use type kill -l to get a list of all available signals.
To kill a process you would use the KILL signal as such: kill -s KILL PID, this would in
effect terminate the process indicated by its PID.
To find out what signal terminated the previous shell command use kill -l $?.
Note that indiscriminate use of kill can get you into trouble, and that you will only be allowed to kil you own processes.
Last modified: Sun Aug 10 11:54:37 BST 1997