A program is a file containing statements or commands in the form of source code or machine code. A process, in Unix terminology, is the execution of a program. By this we mean the running of a program, not a blindfold, a cigarette, and firing squad. A program is an object. A process is an action utilizing that object. A grocery list is like a program. A trip to the grocery store to buy what is on the list is like a process.

Unix is a multitasking system, which means that many processes can be running at any given moment, i.e. there can be many active processes.

When you log in, the system creates a new process to run your shell program. The same happens when other people log in. Hence, while everyone may be using the same shell program, they are all running different shell processes.

When you run a program (a command) from the shell, the shell creates a new process to run the program. Hence, you now have two processes running: the shell process and the command's process. The shell then normally waits for that child process to complete before printing the shell prompt again and accepting another command.

The process created by the shell to run your command is called a child process of the shell process. Naturally, the shell process is then called the parent process of the command process.

Each process is uniquely identified by an integer serial number called the process ID, or PID.

Unix systems also keep track of each process's status and resource usage, such as memory, CPU time, etc. Information about your currently running processes can be viewed using the ps (process status) command:

shell-prompt: ps
 PID TTY           TIME CMD
7147 ttys000    0:00.14 -tcsh
7438 ttys000    0:01.13 ape notes.dbk unix.dbk
7736 ttys001    0:00.13 -tcsh

Example 3.6. Practice Break

Run the ps command. What processes do you have running?

shell-prompt: ps

What if we want to see all the processes on the system, instead of just our own? On most systems, we can add the -a (include other peoples' processes) and -x (include processes not started from a terminal) flags.

shell-prompt: ps -ax

Another useful tool is the top command, which monitors all processes in a system and displays system statistics and the top (most active) processes every few seconds. Note that since top is a full-terminal command, it will not function properly unless the TERM environment variable is set correctly.

Example 3.7. Practice Break

Run the top command. What processes are using the most CPU time? Type 'q' to quit top.

shell-prompt: top



Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
  1. How does a process differ from a program?

  2. If 10 people are logged in and using the same Unix shell, how many shell programs are there? How many shell processes?

  3. What normally happens when you run a program from the shell?

  4. How are processes identified in Unix?

  5. Show a Unix command that lists all the processes currently running on the system.

  6. Show a Unix command that monitors which processes are using the most CPU and memory resources.