Job Process Control

A process is an instance of an executed program. A job is a process running in your current shell in your current login session. You can use several shell commands to manipulate jobs. Once you have closed your current shell or exited your current login session, jobs may continue to run. You will have to use UNIX commands explained below to manipulate any processes you may have left behind.

Starting Jobs

You can start a job in the foreground or background. If you run a job in the background and then logout or close the current shell, you will not be able to bring the job to the foreground again. The job can, however, continue to produce output to a file once you have logged out or closed the shell.

Running Jobs in the Foreground

To start a job in the foreground, simply type in the command at the Unix prompt and then hit return. When you start a job in the foreground, you will notice that you do not get a prompt back, but instead, your cursor is left hanging below your last prompt. You can only have one job running in the foreground at a time.

Running Jobs in the Background

There are two ways to start a job in the background. First, you can select the command from the root menu in Open Windows or X Windows. Second, you can type in the command at the Unix prompt, followed by an ampersand (&) symbol:

    command &
    Example: netscape &

When you start a job in the background, you will notice that you do get a prompt back and at that point, you can enter more commands.

Listing Jobs

To see a list of all the jobs you have running from your current shell, type:

    jobs

You will see something like the following:
[1] Running xclock
[2] - Suspended xcalc
[3] + Suspended xrolo
[4] Running xeyes

The first column contains the job number, the second column describes whether the job is running or suspended, and the last column gives the name of the job. The ‘+’ symbol indicates the current job (the job most recently stopped or put into the background). The ‘-‘ symbol indicates the previous job.

Suspending a Job

There are two ways to suspend a job. First, if a job is running in the foreground, you can put your cursor in the window where you started the job and type ^Z (hold down the Ctrl key and press the ‘z’ key). This will suspend the job that was running in the foreground.

Second, if a job is running in the background, you can type:

    stop %job#

You get the job# from the “jobs” command.

The following example will suspend job# 3.

    Example: stop %3

Restarting a Suspended Job

Once a job has been suspended, you can restart it in the foreground or background. To restart a job in the foreground, type:

    fg %job#

The following example will restart job# 3 in the foreground. If you restart a job in the foreground, you will not get a prompt back.

    Example: fg %3

To restart a job in the background, type:

    bg %job#

The following example will restart job# 4 in the background. If you restart a job in the background, you will get a prompt back and you will be able to execute more commands.

    Example: bg %4

Killing a Job

To kill a job, type:

    kill %job#

The following example will kill job# 4.

    Example: kill %1

Listing Processes

To see a list of all the processes you have running from your current login session, type:

    ps

You will see something like:
PID TT S TIME COMMAND
3805 pts/2 T 0:00 xrolo
3804 pts/2 T 0:00 xcalc
3667 pts/2 S 0:03 tcsh
3848 pts/2 S 0:00 xeyes
3849 pts/2 O 0:00 ps
3803 pts/2 T 0:00 xclock

  • The PID is the process ID number.
  • TTY shows the controlling terminal for the process. A ‘?’ is printed when
    there is no controlling terminal.
  • The S column shows the state of the process, given as a single O, S, R, Z, or T, as described below:

    O Process is running on a processor.

    S Sleeping: process is waiting for an event to complete.

    R Runnable: process is on run queue.

    Z Zombie state: process terminated and parent not waiting.

    T Process is stopped, either by a job control signal or because it is being traced.

  • TIME shows the total execution time for the process.

To see a list of all the processes you have running on the current host, including processes from previous login sessions:

On Solaris, type:

    ps -aux | grep <username>

For a listing of all of the options that may be used with ps, type:

    man ps

You may also use the ptree command to list your processes. Enter:

    ptree <username>

This will show the children processes indented from their respective parent processes.

Killing Processes

To kill a process, type:

    kill pid#

You can find the pid# by listing your processes using the ps command.

    Example: kill 3803

The above example will send a message to the process asking the process to kill itself. Sometimes processes get left in a hung state and do not accept messages. If this is the case, you will have to use the following option in order to kill it:

    kill -9 pid#
    Example: kill -9 3803

The -9 option will “pull the plug” on the process so to speak. This option might leave some locked files or child processes behind and is therefore only recommended if kill by itself does not work.