Bash job control

Source: Internet
Author: User

Bash job control

Job control is a powerful function provided by bash Shell. It allows you to choose whether to run a program, that is, a job, on the foreground or in the background.

1. Enable bash job control.

# Set-o monitor
Or
# Set-m

2. Jobs displayed in the background

# Jobs
[1]-running gedit &
[2] + running sleep 1000 &
+ Indicates the job that is last run in the background.
-Indicates the second to last job to be run in the background.

# Jobs-l // The PID is displayed.
[1]-3403 running gedit &
[2] running sleep 3408 &

# Jobs % // display the recently executed commands in the job table
[2] + running sleep 1000 &

# Jobs-r // list all running jobs

# Jobs-s // list all pending (paused) jobs

3. Job control: fg and bg commands

# Gedit & // drop the job to the background for execution
[1] 15465

# Fg % 1 // put the job to the foreground for execution
Gedit

^ Z // send the foreground job to the background and suspend (pause execution). A prompt is displayed.

# Bg % 1 // start job 1 that stops in the background

# Kill % 1 // kill job 1
# Kill-9% 1 // force kill job 1
Common kill signals:
-1: re-read the parameter configuration file (similar to reload );
-2: represents the same action as entering [ctrl]-c on the keyboard;
-9: immediately force a job to be deleted;
-15: Terminate the work of a worker as a normal program. It is different from-9.

# Disown % 1 // remove Job 1 from the job table. shell does not recognize it as an available job (as a normal process, which can be viewed by ps)

4. Terminal background and system Background

In terminal mode, jobs put in the background through & or ^ Z are put in the background of the terminal, rather than the background of the system. When the background task is not completed and the terminal exits, the background task is terminated.
The system background tasks are not terminated with the termination of the terminal, and are irrelevant to the terminal.
You can run the at command or nohup command in the background of the system. After you exit the terminal or log out of the system, the program can continue to run.
The output of the program running through nohup is redirected ~ /Nohup. out file.
Nohup does not support Bash built-in commands, but only external programs.

# Nohup cmd
# Nohup cmd &

Bash Functions

Aesthetics and Philosophy in Linux Bash Script Programming Language

Top 10 bash skills to improve Linux Efficiency

Bash logon and welcome information:/etc/issue,/etc/motd

Several common configuration files in Bash

Bash script 15-minute advanced tutorial

Job control instances of Bash and KSH shell in 10 Linux/Unix

Abnormal shell script running in Ubuntu: difference between Bash and dash

Bash script for statement if statement and various test statements

What is the Bash Shell build in command?

Share useful bash aliases and functions

Linux Bash Shell getting started

This article permanently updates the link address:

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.