Job control (Unix): Difference between revisions

Content deleted Content added
Edit for accuracy
Edit for uniformity and accuracy; highlight diff between fg and wait
Line 3:
In a [[Unix]] or [[Unix-like]] [[operating system]], '''job control''' refers to controlling a [[process group]] as a [[job (computing)|job]] via a [[Unix shell| shell]]. Control features include suspend, resume, and terminate, and more advanced features can be performed by sending a [[signal (computing)|signal]] to a job. Job control allows a user to manage processing in the Unix-based [[multiprocessing]] environment, and is distinct from [[job control (computing)|general computing job control]].
 
[[POSIX]] specifies job control commands {{endash}} modeled after the Korn shell job control commands.<ref>{{man|cu|bg|SUS}}; {{man|cu|fg|SUS}}.</ref>. Command {{code|bg}} resumes the foreground job paused via {{keypress|Control|Z}} as a background job. Command {{code|fg}} causes the background job to run in the foreground; either the job specified or the one most recently sent the background if none specified. Command [[wait (command)|<code>wait</code>]] pauses the interactive session untilfor the specified background jobs to complete. Specifyingor no jobs selectsfor all background jobs of the active shell if none is specified.<ref>{{cite web | last=Kerrisk| first=Michael |date=Feb 2, 2025 |title=wait(1p) — Linux manual page |website=man7.org |url=https://www.man7.org/linux/man-pages/man1/wait.1p.html |publisher= |access-date=May 13, 2025}} </ref>
 
Job control was first implemented in the [[C shell]] by Jim Kulp,<ref>
Line 22:
 
==Overview==
In a shell, a user has one foreground processjob but can run multiple processesjobs 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 process. The user interactively enters a command and the implementation of the command (often a program) controls [[standard streams |input and output]] such that the user cannot access the shell until the command completes or the user interrupts it (i.e. via {{keypress|Control|C}}).
 
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 process in the background, send a running processes to the background, bring a background process to the foreground, and suspend or terminate a process.