Job control
Encyclopedia
On operating systems that support executing multiple process
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

es in parallel or in series (batch processing
Batch processing
Batch processing is execution of a series of programs on a computer without manual intervention.Batch jobs are set up so they can be run to completion without manual intervention, so all input data is preselected through scripts or command-line parameters...

), job control refers to the orchestration of multiple batch jobs.

Unix shell

When using Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 or related operating systems via a terminal
Computer terminal
A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...

, a user will initially only have a single process running, their login
Logging (computer security)
In computer security, a login or logon is the process by which individual access to a computer system is controlled by identifying and authentifying the user referring to credentials presented by the user.A user can log in to a system to obtain access and can then log out or log off In computer...

 shell
Unix shell
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems...

. Most tasks (directory listing, editing files, etc.) can easily be accomplished by letting the program take control of the terminal and returning control to the shell when the program exits; however, sometimes the user will wish to carry out a task in the background while using the terminal for another purpose. Job control is a facility developed to make this possible, by allowing the user to start programs in the background, send programs into the background, bring background programs into the foreground, and start and stop running programs. Processes
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

 under the influence of a job control facility are referred to as jobs.

History

Job control was first implemented in the C shell
C shell
The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...

 by Jim Kulp, then at IIASA
IIASA
The International Institute for Applied Systems Analysis is an international research organization located in Laxenburg, near Vienna, in Austria. IIASA conducts interdisciplinary scientific studies on environmental, economic, technological and social issues in the context of human dimensions of...

 in Austria, making use of features of the 4.1BSD kernel. The facility was then incorporated into the Bourne shell
Bourne shell
The Bourne shell, or sh, was the default Unix shell of Unix Version 7 and most Unix-like systems continue to have /bin/sh - which will be the Bourne shell, or a symbolic link or hard link to a compatible shell - even when more modern shells are used by most users.Developed by Stephen Bourne at AT&T...

, and exists in most modern Unix shells.

Implementation

  • Typically, the shell keeps a list of jobs in a job table. A job consists of all the members of a pipeline
    Pipeline (Unix)
    In Unix-like computer operating systems , a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one. Each connection is implemented by an anonymous pipe...

    ; thus all the processes constituting the job will be in the same process group
    Process group
    In POSIX-conformant operating systems, a process group denotes a collection of one or more processes. Process groups are used to control the distribution of signals. A signal directed to a process group is delivered individually to all of the processes that are members of the group.Process groups...

    .
  • A program can be started as a background task by appending & to the command line; its output is directed to the terminal (potentially interleaved with other programs' output) but it cannot read from the terminal input.
  • A task running in the foreground can be stopped by typing the suspend character (Ctrl-Z); this sends SIGTSTP
    SIGTSTP
    SIGTSTP is a signal in a Unix computer system that tells a program to stop temporarily. On POSIX-compliant platforms, SIGTSTP is the signal sent to a process by its controlling terminal when the user requests that the process be suspended. The symbolic constant for SIGTSTP is defined in the header...

     to the process group and returns control to the shell.

  • A stopped job can be resumed as a background job with the bg
    Bg (Unix)
    bg is a job control command in Unix and Unix-like operating systems that resumes execution of a suspended process without bringing it to the foreground; the resumed process continues to execute in the background without receiving user input from the terminal. bg is required to be included in an...

     builtin
    Shell builtin
    In computing, a shell builtin is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute....

     or as the foreground job with fg
    Fg (Unix)
    fg is a job control command in Unix and Unix-like operating systems that resumes execution of a suspended process by bringing it to the foreground and thus redirecting its standard input and output streams to the user's terminal...

    ; in either case the shell redirects I/O
    Input/output
    In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world, possibly a human, or another information processing system. Inputs are the signals or data received by the system, and outputs are the signals or data sent from it...

     appropriately and sends SIGCONT
    SIGCONT
    On POSIX-compliant platforms, SIGCONT is the signal sent to restart a process previously paused by the SIGSTOP or SIGTSTP signal. The symbolic constant for SIGCONT is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.-Etymology:SIG...

     to the process.
  • jobs will list the background jobs existing in the job table, along with their job number and job state (stopped or running).
  • The kill builtin (not /bin/kill) can signal jobs by job ID as well as by process ID: jobs specified by a job ID should be killed by prefixing "%". Kill can send any signal to a job, however if the intent is to rid the system of the processes the signals SIGKILL
    SIGKILL
    On POSIX-compliant platforms, SIGKILL is the signal sent to a process to cause it to terminate immediately. The symbolic constant for SIGKILL is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms, however on the vast majority of...

     and SIGTERM
    SIGTERM
    On POSIX-compliant platforms, SIGTERM is the signal sent to a process to request its termination. The symbolic constant for SIGTERM is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms, however on the vast majority of systems,...

     (the default), are probably the most applicable. A task running in the foreground can be permanently suspended by typing the kill character (Ctrl-C).
  • disown can be used to remove jobs from the job table, converting them from jobs into daemon
    Daemon (computer software)
    In Unix and other multitasking computer operating systems, a daemon is a computer program that runs as a background process, rather than being under the direct control of an interactive user...

    s so that they continue executing when the user logs out.

Job ID

A job ID is a token used to identify jobs to shell builtin
Shell builtin
In computing, a shell builtin is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute....

s. Job IDs begin with the % character; %n identifies job n, while %% identifies the current job. Other job IDs are specified by POSIX.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK