Shell job control

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.