UNIX Usage Guidelines, Part II
J.T. Frey, 04/25/2001

  (1.1) What is UNIX?
  (1.2) Connecting to the SGI's from Another Computer
  (1.3) Disk Space: Your Home Directory
  (1.4) Getting Help
  (1.5) Working In and Moving Through Directories
  (2.1) Processes: How Work Is Done

Processes: How Work Is Done
As discussed previously, UNIX is a multiuser operating system, which means users must share the computing power in order to get things done. One of the features which makes UNIX such a powerful operating system is the fact that it doles out processor time very well.

When you attempt to run a program on a UNIX machine -- whether it be a text editor, a web browser, or a computational package like Gaussian -- many things take place. First, UNIX creates a new process and assigns it a unique process identification number (PID). The process is the operating system's way of controlling how often the program is allowed to do something. UNIX then reads the program's executable file. The executable file holds the commands which are sent to the machine's processor. For it to appear as though many programs are running simultaneously, UNIX switches back and forth very quickly, giving each process tiny bits of time to send instructions to the CPU. How much time each process is given depends upon its priority. When the program is finished, UNIX destroys the process and its PID is invalidated (it may later be assigned to another program, though).

UNIX has commands which allow you to view information about all of the processes which are running. The primary command is the ps command. If you type this command and press return, UNIX will list all of the processes which you've started since you logged in which are still running:
chem 11% ps
       PID TTY     TIME CMD
    131129 ttyq5   0:00 tcsh
    216908 ttyq5   0:00 ps
chem 12%
The ps command has many options which you may use, one of which bears mentioning here. It is entirely possible for you to have processes running even when you are not logged in to a UNIX computer. Because such a process was started prior to your current log in to the machine, it will not appear if you type just ps. You can get a list of every process running on the machine which is owned by you by adding the -u option followed by your username:
chem 12% ps -u frey
       PID TTY     TIME CMD
    101254 ?      10:21 l502.exe
    131129 ttyq5   0:00 tcsh
    216909 ttyq5   0:00 ps
chem 13%
Notice that in this case I can now see that I have a Gaussian job running (l502.exe). The column headed by TIME shows how much time a given process has accumulated. Accumulated time corresponds to how much time UNIX has given a process, not how long the process has been active. In other words, the value in the TIME column is not a measure of the actual time that has elapsed since you started the program in question. Remember I mentioned that every process is assigned a unique number? This number, the PID, is visible in the PID column!

Another command you can use to view processes on a computer is top. This command will produce a list of all the active processes on the machine, typically sorted by the percentage of the computer's processing power which it is using. A moment ago I told you that UNIX doles out little slices of CPU time to all of the processes. This is true, but UNIX is even smarter than to do just that: if a program does not need any CPU time, UNIX doesn't give it any! So there may be many processes listed, but most of the time only a few of them will be using a significant amount of the CPU time. The top command will show you what processes are using the power:

The image above shows a sample of the output from the top command. The header at the top lists information about: the total number of processes active on the computer, the number of CPUs in the computer, the distribution of the percentage of CPU "power", and memory information. Under this header is the listing of processes. The columns of note are first the PID of each process, the username of the person who started the process, the amount of CPU time the process has accumulated, the relative percent of time a CPU is devoting to the process (the CPU% column) and the command associated with the process.

You may be wondering what's the big deal with giving each process a PID, if the computer keeps track of all this stuff then why does it need a PID? The answer is simple: you the user need a way of telling the computer what process you're referring to at times. One of these times is when you need to end a process prematurely. Let's say I figure out that the Guassian job listed when I did the ps -u frey command is not something I need to be running. If I want to tell the computer to end that process, I tell it to kill the process by referencing its PID:
chem 13% ps -u frey
       PID TTY     TIME CMD
    101254 ?      11:05 l502.exe
    131129 ttyq5   0:00 tcsh
    216912 ttyq5   0:00 ps
chem 14% kill 101254
chem 15% ps -u frey
       PID TTY     TIME CMD
    131129 ttyq5   0:00 tcsh
    216914 ttyq5   0:00 ps
chem 16%
You should be aware of the fact that you can only kill processes which have your username associated with them; picking a process listed by the top command which is not your own and attempting to kill it will result in an error message and gentle scolding from UNIX.
Back to previous page.

Answers to Questions