UNIX Primer

Home | Primer Home

Playing With Processes

Everything that 'runs' in UNIX is represented as a 'process.' For instance, the shell you are running is one process. If you execute a command from the shell, a process is created for that command. We can see what processes we are running with the 'ps' command. Note that generally, you only interact with one process at a time. This process is called the 'foreground' process. All other processes that are running are said to be running in the 'background'.

If we are running a process in the foreground and we would like to terminate it, we can hit 'CTRL-C'. This is often helpful when a process stops responding because it is in an infinite loop, resources are low, or some other glitch has occurred.

If we would like to terminate a process in the background, we can 'kill' the process. Locate the process ID number by running 'ps' and then type 'kill processID'. This is equivalent to typing CTRL-C while running that program in the foreground.

If we are running a process and we would like to interrupt it temporarily, but not end it, we can hit 'CTRL-Z'. This takes a process in the 'foreground' and puts it in the 'background.' In other words, the process stops running for now, but can be resumed later. Note that a number is shown next to the process identification number. To return to this process, we can type 'fg #' where # is that number. To make this program continue running while in the background, we can type 'bg #'. If we want to operate on a program we just suspended, we can just use 'fg' or 'bg' respectively.

Related Commands:

ps Process Status Shows currently running processes.

kill To send interrupt (kill) signal to processes.
kill <processID>
kill -9 <processID>
  • Use the first syntax to try to terminate a backgrounded process.
  • The second syntax can be used to force termination if the first does not work.

fg ForeGround Returns a background process to the foreground.
fg [#]

bg BackGround Continues executing suspended process in the background.
bg [#]

Designed by D. Kaminsky
Edited by Diana Palsetia
© University of Pennsylvania, 2008