Job Control
Bash can run jobs in the background or in the foreground. A running Program It is called a process or job. Each process has a process ID, PID. Generally, all programs run on the foreground. You can use Ctrl + D to send a signal to pause the program. A paused process can be run in the background, sent back to the foreground, or terminated.
[Root @ localhost ~] #VI# Open the VI editor and press Ctrl + Z to pause it. [1] + stopped vi [Root @ localhost ~] # Sleep 400 & # Add &, indicating running in the background [2] 5277 [Root @ localhost ~] # Jobs # Display the current job in the background [1] + stopped vi [2]-running sleep 400 & [Root @ localhost ~] # Jobs-l # Display the current job and PID in the background [1] + 5276 stopped vi [2]-5277 running sleep 400 & [Root @ localhost ~] # Jobs % # Display commands recently added to the job table [1] + stopped vi [Root @ localhost ~] # FG % 1 # FG transfers the job with job number 1 to the foreground [Root @ localhost ~] # Kill % 1 # Killing a job with job number 1 VIM: Caught deadly signal term VIM: finished. |
Job control commands
Command |
Description |
BG |
Start a terminated background job |
FG |
Transfer background jobs to the foreground |
Jobs |
List all running jobs |
Kill |
Sends a kill signal to a specified job |
Stop |
Suspends a background job. |
Stty tostop |
When a background job sends an output to a terminal, it is suspended. |
Wait [N] |
Wait for a specified job and return its exit status. Here N is a PID or job number. |
∧ Z (CTRL-Z) |
Terminate (suspend) A Job. A prompt appears on the screen. |
|
|
Parameters of the jobs command |
Description |
% N |
Task No. N |
% String |
Job name starting with string |
%? String |
Job name contains string |
% |
Current job |
% + |
Current job |
%- |
The first job of the current job. |
-R |
List all running jobs |
-S |
List all pending jobs |