Job and 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.
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:
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.
To see a list of all the jobs you have running from your current shell, type:
You will see something like the following:
 Running xclock
 - Suspended xcalc
 + Suspended xrolo
 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:
You get the job# from the "jobs" command.
The following example will suspend job# 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:
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.
To restart a job in the background, type:
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.
Killing a Job
To kill a job, type:
The following example will kill job# 4.
To see a list of all the processes you have running from your current login session, type:
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
PIDis the process ID number.
TTYshows the controlling terminal for the process. A '?' is printed when there is no controlling terminal.
Scolumn shows the state of the process, given as a single
O, S, R, Z, or
T, as described below:
OProcess is running on a processor.
SSleeping: process is waiting for an event to complete.
RRunnable: process is on run queue.
ZZombie state: process terminated and parent not waiting.
TProcess is stopped, either by a job control signal or because it is being traced.
TIMEshows 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
You may also use the
ptree command to list your processes. Enter:
This will show the children processes indented from their respective parent processes.
To kill a process, type:
You can find the pid# by listing your processes using the
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#
kill -9 3803
-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.
February 04, 2011