$title = "Managing Jobs and Processes"; $area = "Unix Support"; $metadata = "unix, job, process, managing, display, ps, pid, foreground, background, fg"; $pfloc = ""; require '/usr/local/wwwdocs/ucs/fragments/header.phtml'; require '/usr/local/wwwdocs/ucs/fragments/header-bc.phtml'; ?>
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).
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.
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).
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.
Redirect the standard output for a command that is being run in the background to a file. This prevents the output from the command appearing on your screen and interrupting your current work. Any error messages will be sent to your screen unless you have redirected standard error.
Do not run an interactive command that requires you to type something at the terminal as a background job. If you do the job will stop and wait for user input. You will then have to kill its process.
To run a foreground process as a background job:
Suspend the foreground process by holding down the Ctrl key and pressing the z key (Ctrl/z).
Enter the bg (background) command to move the process into the background.
For example:
lpr -Pps23 part[1-8].ps Ctrl/z Stopped bg [1] lpr -Pps23 interface.ps & jobs [1] Running lpr -Pps7 interface.ps
This starts a foreground process to print several files. The process is then stopped and the job moved into the background. The state of this job is then checked.
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.
require '/usr/local/wwwdocs/ucs/fragments/footer.phtml'; ?>