How Linux runs the process in the background and does not close with the terminal shutting down

Source: Internet
Author: User

Reference: http://www.cnblogs.com/kaituorensheng/p/3980334.html

Use the command nohup:no hang up to indicate that the process does not close with the terminal when the terminal is closed

FG, BG, Jobs, &, Nohup, CTRL + Z, CTRL + C command

First, &

At the end of a command, you can put this command in the background to execute, as

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

Two, CTRL + Z

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

Third, Jobs

See how many commands are running in the background at the current terminal

The JOBS-L option shows the Pid,jobs status of all tasks can be running, stopped, Terminated. However, if the task is terminated (kill), the shell removes the process identity of the task from the list known to the current shell environment.

Iv. FG

The commands in the background are moved to the foreground to continue running. If there are multiple commands in the background, the selected command can be paged out with FG%jobnumber (which is the command number, not the process number).

V. BG

A command that pauses in the background changes to execute in the background . If there are multiple commands in the background, you can use BG%jobnumber to bring up the selected command.

Vi. Kill

    • Scenario 1: View the job number (assuming num) with the jobs command and then execute the kill%num
    • Scenario 2: View the Job's process number (PID, assuming PID) with the PS command and then execute the kill PID

Termination of the foreground process: Ctrl + C

Seven,nohup

If the program is always executed in the background, even if the current terminal is closed (& cannot be done before), Nohup is required. This command can continue to run the process after you exit the account/close the terminal. After the interruption, the other terminal jobs can not see the background running program, at this time using PS (Process view command)

"test.sh #a: Show All Programs U: Show x in user-oriented format: Show All Programs, do not differentiate by terminal 

How Linux runs the process in the background and does not close with the terminal shutting down

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.