Content deleted Content added
Stevebroshar (talk | contribs) Edit for uniformity and accuracy; highlight diff between fg and wait |
Stevebroshar (talk | contribs) →Overview: use job vs process more consistently |
||
Line 22:
==Overview==
In a shell, a user has one foreground job but can run multiple jobs in the background. Many operations (i.e. listing files) are relatively quick so the user can wait for a response with little down time and some operations (i.e. editing) require interaction only possible via a foreground
However, a user may wish to perform an operation while using the shell for another purpose. An operation that is running but not using the interactive input and output is running in the background. The single operation that is using the interactive input and output is running in the foreground. Job control is the facility to control how operations run as foreground or background. A user can start a
A job maps to a single shell command execution which may result in multiple processes starting and completing. Multi-process operations come about because a process may create child processes, and a single shell command may consist of a [[Pipeline (Unix)|pipeline]] of multiple communicating processes. For example, the following command line selects lines containing the text "title", sorts them alphabetically, and displays the result in a [[terminal pager]]: <code>grep title somefile.txt | sort | less</code>. This creates at least three processes: one for [[grep|{{code |grep}}]], one for {{code |sort}}, and one for [[less (Unix)|{{code |less}}]]. Job control allows the shell to control these related processes as one entity, and when a user issues the appropriate key combination (usually {{keypress |Control|Z}}), the
A job can
Job control and
▲A job can be referred to by a [[Handle (computing)|handle]]{{efn|A job ID is an abstract reference by the shell to a resource (a process group) managed externally, by the operating system, hence is a handle.}} called the ''job control job ID'' or simply ''{{visible anchor|job ID}}'', which is used by [[shell builtin]]s to refer to the job. A job ID begin with the <code>%</code> character; <code>%n</code> identifies job ''n'', while <code>%%</code> identifies the current job. Other job IDs are specified by [[POSIX]].<ref>IEEE Std 1003.1-2001, [http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_203 Section 3.203, Job Control Job ID]</ref> In informal usage the number may be referred to as the "job number" or "job ID", and Bash documentation refers to the (%-prefixed) job ID as the ''jobspec.''<ref>[https://www.gnu.org/software/bash/manual/html_node/Job-Control-Basics.html#Job-Control-Basics 7.1 Job Control Basics]</ref>
▲Job control and job IDs are typically only used in interactive use, where they simplify referring to process groups; in scripting PGIDs are used instead, as they are more precise and robust, and indeed job control is disabled by default in bash scripts.
==Implementation==
|