Linux background running and closing, view background tasks

  

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

one, &

At the end of a command, you can put this command in the background, such as
? 1 watch -n 10 sh test.sh & # execute the test.sh script every 10s in the background

Second, ctrl + z< Br>

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

3, jobs

See how many commands are currently running in the background

The jobs -l option displays the PIDs of all tasks. The status of jobs can be running, stopped, Terminated. But if the task is killed, the shell removes the process ID of the task from the list known to the current shell environment.

Four, 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 (which is the command number, not the process number) to call the selected command.


Five, bg

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

Sixth, kill
method 1: View the job number through the jobs command (assumed to be num), and then execute kill %num method 2: View the job number of the job (PID, assuming pid) through the ps command , then execute kill pid

termination of the foreground process: Ctrl+c

7. nohup

If the program is always executed in the background, even if the current terminal is closed (previous & Can't do it, this time you need nohup. This command can continue to run the corresponding process after you log out of the account/close the terminal. After closing the interrupt, the other terminal jobs can no longer see the background running program, then use ps (process view command)
? 1 ps -aux |  Grep "test.sh" #a: Display all programs u: Display x in user-based format: display all programs, not differentiated by terminal

End of process:

Background process Termination:

Transfer from: http://www.cnblogs.com/kaituorensheng/p/3980334.html

Copyright © Windows knowledge All Rights Reserved