Simple Unix commands: Information about processes

In the examples text shown in bold type needs to be replaced by text of your own, for example the name of the command or topic on which you are looking for help.

Everything else should be typed literally as given in the examples, using lower- and upper-case as shown. (Almost everything in Unix is in lower-case.)

At the end of each command you must press the Return key.


What is a process?

Whenever you run a program on one of the Sun workstations you initiate a new process. Every process is identified by a number, known as the Process ID or pid. Every process is owned by a particular user: as a rule processes that you initiate are owned by you.

The commands described below are used for finding out what is happening on the system on which you are currently logged in -- ie the system which appears in the Unix prompt. If you are logged in on langs and want to know what is happening on psych you will have to do a "remote login" to psych, using the command:

        rlogin psych


To see all processes currently owned by you

Type the simple command
        ps
This will usually give a response like this:
  PID TT STAT  TIME COMMAND 
 1772 q4 R     0:00 -tcsh (tcsh)
 1803 q4 R     0:00 ps
This shows that you currently have two processes: the first (tcsh) is the process which is initiated when you login to the Sun; the second (ps) is the process you initiated by giving the ps command.

The ps command will tell you if you have left yourself logged on elsewhere. For example the following listing tells you that you have a second tcsh process and a Pine process.

  PID TT STAT  TIME COMMAND
 1772 q4 S     0:00 -tcsh (tcsh)
 1892 q4 R     0:00 ps
 1849 q5 S     0:00 -tcsh (tcsh)
 1887 q5 S     0:00 /usr/local/bin/pine3.96

Shutting down unwanted processes

You can shut down unwanted processes using the kill command. You can do this if you have left yourself logged in somewhere else, or if your screen has frozen on one terminal and you are logged in from another. For example
        kill 1849
will shut down the process whose PID is 1849.

After giving the kill command you should use ps again to make sure it has worked. If it doesn't work you can use the -9 switch -- eg

        kill -9 1849
Naturally you can only use the kill command to shutdown your own processes, unless you have super user privileges.


To see all the processes on the system

There are numerous switches that can be used with the ps command to modify the way it behaves. For example
        ps -af
will give a list with details of all the processes currently active on the system. Because it is likely to be a long list, you should usually use the "pipe to more" facility:
        ps -af | more

You can also search for particular sorts of process using the grep command. grep searches for a given string of characters within a file. If you "pipe" the output from ps into grep it will search for a string and only display those lines on which the string occurs.

For example

        ps -af | grep pine
will show you all the people who are using pine on the system:

jmy       359  0.0  0.0  848    0 q9 IW   May  2  0:46 /usr/local/bin/pine3.96
wc2     24776  0.0  0.0  836    0 q0 IW   May  2  0:41 /usr/local/bin/pine3.96
cdl      1485  0.0  1.8  624  540 q2 S    18:33   0:07 /usr/local/bin/pine3.96
sz       2280  0.0  0.0  692    0 p7 IW   18:51   0:05 /usr/local/bin/pine3.96
pcu      2737  0.0  0.7   32  204 q4 S    19:00   0:00 grep pine
igm      1690  0.0  5.3  696 1616 p8 S    18:39   0:09 /usr/local/bin/pine3.96
Look in the man pages for ps for information on the various columns in this display.


Listing the users on the system

To see a list of the users currently logged on to the system, type
        users
You will get a response like this:
adb2 bfw cr14 ef2 igm jmy kd4 ngm1 ngm1 pcu pcu smt2 smvp sz tk6 wc


The process environment

Some programs need to have certain "environment variables" set up so that they can run. These are often set up by a specially written "setup" script, or else you can set them up yourself using setenv.

For example, Ingres requires some additions to be made to the PATH environment variable. These are done with the setup ingres command.

to get a list of the current environment variables and their values

Use the env command.

For example, use the following sequence of commands to find the value of the PATH environment variable before and after setting up Ingres:

        env
        setup ingres
        env
The "env" command might give more information than can fit on a single screen, so you should use the "pipe to more" option: env | more

Julian Crowe
3rd May 1997
Simple Unix commands: contents page IT training page