University Systems --> Deans --> All Deans Pages --> Processes under Unix -->

Processes under Unix

This section is a intended for advanced UNIX users who are interested in learning how the kernel, shell, and other programs interact from the system's point of view. It is not intended to be a complete discussion of processes and signals in a UNIX system, but is a short overview of how things work.


How Processes are started

Each program running on a UNIX machine exists as a process within the operating system. All processes (with the exception of the first process) are created by another process using a fork system call, fork is the only way to create a new process. Processes are hierarchical; there is an init process that gets started when the system boots, and all other processes, including shells, user programs, and system daemons, are spawned from this.

A process that makes a call to fork (called a parent process), spawns off another process (called a child process) that is an exact copy of the parent process. Both processes continue from the return of the call to fork. The shell makes use of this in conjunction with the exec system call (actually, there a suite of exec calls, see exec(2)). The exec system call takes among it's arguments an external program which it will execute. The process then calls a program using exec and is completely replaced by the new running program. The shell provides several ways to launch a process, each having a specific purpose.

The first is simply using exec without using fork. Csh provides the built in exec command (that is it not a UNIX command, it is a shell command, so you will find the documentation for it in the csh(1) man page). This has the effect or replacing the shell with the program, and when the program ends, so does the login session.

The most common way the shell launches a program is the fork and exec sequence, with the parent process (the shell), sitting in the background waiting for the child process to complete (or change state), before it regains control of the terminal and continues. For example, if you start a text editor from the command line, it will be in the foreground, and the shell will "sleep" until you either exit or suspend the editor. This is what happens when you run a program "normally".

A third way is to use the fork/exec sequence, but the shell stays in control of the terminal and does not wait for the process to finish. The new program is then running independently and has no interaction with the user. Output will go to the screen, and any input needed will cause the program to be suspended until the user brings it into the foreground. This happens when you start a job in the background. The most common way to do this is to follow the command name with an ampersand, as discussed in the section on job control.

How do I:
How are we doing? Comments on this page?
Office of Information Technology
Office of Information Technology Help Desk Web Site University of Maryland Web Site Office of Information Technology Web Site