Detailed Linux background running and shutdown, viewing background tasks _linux

Source: Internet
Author: User
Tags terminates

FG, BG, Jobs, &, Nohup, Ctrl+z, CTRL + C command

First, &

Added at the end of a command, you can put this command in the background to perform, such as

Watch-n sh test.sh & #每10s在后台执行一次test. Sh script

Two, CTRL + Z

A command that is executing in the foreground can be placed in the background and paused.

Third, Jobs

See how many commands are currently running in the background

The JOBS-L option shows that the pid,jobs status of all tasks can be running, stopped, terminated. But if the task is terminated (kill), the shell removes the task's process identity from the list known to the current shell environment. In other words, the jobs command displays the task information that is running or being suspended in the background of the current shell environment;

Iv. FG

The commands in the background are moved to the foreground to continue running. If you have more than one command in the background, you can use FG%jobnumber (the command number, not the process number) to pull the selected command.

Five, BG

A command that is paused in the background becomes a continuation of the execution in the background. If you have more than one command in the background, you can use the BG%jobnumber to pull the selected commands out.

To move a task to a background run:

CTRL + Z, then BG, so that the process is moved to the background, and the terminal can continue to accept the command.

Concept: Current Tasks

If the background task number has 2, [1],[2]; If the first background task is executed successfully and the second background task is still in progress, the current task automatically becomes the background task of the background task number "[2]". So you can draw the point that the current task is going to change. When a user enters commands such as FG, BG, and stop, the current task is changed if no quotes are added.

VI. Kill

    • 1: View the job number (assuming num) through the jobs command, and then execute the kill%num
    • Way 2: Through the PS command to view the job process number (PID, assumed to be PID), and then execute kill PID

Termination of foreground process: Ctrl + C

Other effects of Kill

In addition to terminating the process, the kill can send other signals to the process, using kill-l to see the signal that the kill supports.

Sigterm is a signal that a kill sends without parameters, meaning that the process terminates, but execution depends on whether the process is supported or not. If the process is not terminated, you can use the Kill-sigkill PID, which is the kernel that terminates the process and the process cannot listen to the signal.

Seven, Nohup

If you want the program to always execute in the background, even if the current terminal is closed (before & cannot), you need to nohup. This command can continue to run the process after you exit the account/close the terminal. After the shutdown interruption, in another terminal jobs has been unable to see the background running program, at this time using PS (Process view command)

Ps-aux | grep "test.sh" #a: Show All Programs U: Show x in user-oriented format: Show All programs, not terminals

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.