Managing jobs and processes

When you enter a command it invokes a program; while this program is running it is called a process. Although there is only one copy of a program, any number of processes can be invoked which run it. Similarly, when you login to the system a process is started to run your shell program. Any processes that are started from within your shell - such as entering a command - are the children of this process. A process can have many children, but only one parent. Each has a unique identifier (PID).

Displaying process information

Process information can be displayed using the ps command:

ps -u username

For example

finan [sparc] 43% ps -u nabc
   PID TTY      TIME CMD
  1264 pts/130  0:00 csh
 18362 pts/108  0:00 csh
 19709 pts/109  0:00 vi
 19235 pts/109  0:00 csh
finan [sparc] 44%

PID is the unique Process IDentifier
TTY is the controlling terminal associated with the process.
TIME is the amount of CPU time used by the process
CMD is the command being executed by the process

You cannot do anything with processes belonging to other users.

Foreground processes

When you enter a command at the shell prompt, your shell forks a child process in which to execute the command.

The parent process (your shell) waits for the command to complete and for its child process to die. Until then you are unable to enter another command. Commands entered in this way are known as foreground processes.

Once the command completes and the child process dies, the parent process is reactivated, the shell prompt returns, and you can enter another command.

To cancel (interrupt) a foreground process, hold down the CTRL key and press the c key (Ctrl/C).

Running processes as background jobs

To run a process in the background as a job and carry on working add an & (ampersand) at the end of the command line. For example:

finan [sparc] 37% who >temp&
[1] 26792
finan [sparc]

The shell forks a child process to run the command and displays the job number ([n]) and the PID (Process IDentifier) number - in this case 26792. The shell prompt returns and you can enter further commands. Background jobs can be listed using the jobs command.

Note that ISS has guidelines regarding the background use of Unix systems.

Placing a foreground process in the background

To run a foreground process as a background job:

Bringing a job into the foreground

To bring a specific background job into the foreground, enter the fg (foreground) command followed by the job number:

fg job_number

If there is only one job running in the background just enter the fg command.

For example:

   lpr -Pps23 interface.ps &
   jobs
   [1]  + Running              xterm -g 90x55
   [2]  - Running              xterm -g 90x55
   [3]    Running              lpr -Pps23 interface.ps
   fg 3
   lpr -Pps23 interface.ps

This starts a process to print a file as a background job. The user then checks the current active jobs and brings the print job - job number three (3) - into the foreground.