Bash's job control

Source: Internet
Author: User

Job control is a powerful feature provided by the Bash shell, which allows you to choose to run the program in the foreground or in the background, which is the job.

1. Open bash's job control function

#set-o Monitor
Or
#set-M

2. Show jobs running in the background

#jobs
[1]-Run in Gedit &
[2]+ Run in Sleep &
+ Represents the last job to be run in the background
-Represents a second-to-last job that runs in the background

#jobs-L//will show PID
[1]-3403 running in Gedit &
[2]+ 3408 running in Sleep &

#jobs%//display the most recently executed command in the job table
[2]+ Run in Sleep &

#jobs-r//list all running jobs

#jobs-S//Lists all pending (paused execution) jobs

3. Operation control: FG and BG Commands

# gedit &//throwing jobs into the background execution
[1] 15465

#fg%1//place job in foreground execution
Gedit

^z//Send foreground job backstage and hang (pause execution), display prompt

#bg%1//Start a background stop job 1

#kill%1//Kill Job 1
#kill-9%1//forced Kill job 1
Kill common signals:
-1: Re-read the configuration file of the parameter (similar to reload);
-2: Represents and by keyboard input [ctrl]-c the same action;
-9: Immediately forcibly delete a job;
-15: Terminate a work in normal program mode. And-9 are not the same.

#disown%1//Removes job 1 from the job table, the shell does not recognize it as an available job (becomes a normal process, PS can view)

4. Terminal background and system background

In terminal mode, jobs placed in the background through & or ^z are placed in the backend of the terminal, not the system background. When the background task is not completed and the terminal exits (exit), the terminal background task terminates.
The tasks in the system background do not terminate with the termination of the terminal, regardless of the terminal.
Jobs can be placed in the system background through the AT command or the Nohup command, and the program can continue to operate after exiting the terminal or logging off the system.
The output of the program running by Nohup is redirected to the ~/nohup.out file.
Nohup does not support bash built-in commands, only external programs are supported.

#nohup cmd
#nohup cmd &

=-=-=-=-=
Powered by Blogilo

Bash's job control

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.