Run and close the CentOS background and view the background task commands

Source: Internet
Author: User
Fg, bg, jobs, & amp;, nohup, ctrl + z, ctrl + c Command 1, & amp; at the end of a command, you can put this command in the background for execution, such as watch-n10shtest.sh & amp; # every 10 s in the background to execute a test. sh script 2, ctrl + z can put a command that is being executed on the foreground to the background and is paused. III,

Fg, bg, jobs, &, nohup, ctrl + z, ctrl + c command

I ,&

At the end of a command, you can put the command in the background for execution, as shown in figure

Watch-n 10 sh test. sh & # execute the test. sh script every 10 s in the background
2. ctrl + z

You can put a command that is being executed in the foreground to the background and be paused.

III. jobs

View the number of commands currently running in the background

The jobs-l option displays the PID of all tasks. jobs can be in the running, stopped, and Terminated states. However, if the task is terminated (kill), shell deletes the process ID of the task from the list known in the current shell environment.

IV. fg

Move the commands in the background to the foreground to continue running. If there are multiple commands in the background, you can use fg % jobnumber (command number, not process number) to call up the selected command.

5. bg

Change a command that is paused in the background to continue execution in the background. If there are multiple commands in the background, you can use bg % jobnumber to call up the selected command.

VI. kill

Method 1: run the jobs command to view the job number (assuming num), and then run kill % num.
Method 2: run the ps command to view the job process number (PID, assumed to be pid), and then run the kill pid command.
Termination of the foreground process: Ctrl + c

VII. nohup

If the program is always executed in the background, it will be executed even if the current terminal is closed (previously & could not be done). nohup is required at this time. This command can continue running the corresponding process after you exit the account/close the terminal. After the interruption is disabled, you can no longer see the program running in the background on the other terminal jobs. in this case, you can use ps (process View command)

Ps-aux | grep "test. sh" # a: show all programs u: Display x in user-based format: show all programs, not distinguished by terminals

Process termination:

Termination of background processes:

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.