Processes and jobs; foreground and background



Last revision August 9, 2004

Table of Contents:

  1. Shell interpretation
  2. Editing command lines
  3. Stuck in a Unix login session?
  4. Program execution
  5. Simple commands
  6. Unix command syntax
  7. Controlling processes
  8. Your login environment

A process is "an instance of a program, with an associated environment, executing in the computer." New processes are always created by having an existing process fork or spawn a child process. The parent process, much like a real parent, can either keep close tabs on the child, waiting for him to finish or controlling his I/O, or disown the child to become a separate detached process.

When you login, the master init process spawns and detaches a child process that becomes the parent process for your login session. This process is an instance of the shell program.

The shell reads the input you type at the terminal to decide when and how to spawn new child processes to run the programs you desire. In the simplest case, your input command to the shell gives the name of a single program and its arguments. The shell spawns a single child process to execute that program (for example, ls) and then waits for that process to finish before processing more input from you. You can keep typing more input which will be saved in a type-ahead buffer, but the shell will not begin processing it until the child process has finished. This type of child process is said to be a foreground process.

You can also create background processes. When the shell starts a background process, that child process is allowed to run by itself while the shell immediately resumes processing more terminal input. The shell does not wait for the background child process to complete; it prompts for more input immediately. You tell the shell to start a process in the background by ending the command line with the ampersand metacharacter (&).

Background processes have several characteristics that differ from foreground processes:

<--Previous Overview Next-->