Linux running, viewing, turn off background programs command

Before writing a reptile crawling Bing home page, you need to run every day crawling, which is soon to be home for the holiday, all computers are not open every day, and thus thinking python program running on a cloud server, which is before writing the download and install the Python Centos7 cloud server Anaconda3 , now thinking about how to make the program hung in the background, and a good memory as bad written, summary records to find information about.


Quick Menu

command Explanation
& The current form of the command station after running
nohup Isolated signal terminal hangs up, the command prefix is
ctrl+z Will turn the background and foreground task freeze
bg The background tasks to freeze up and running again
fg The background task to re-turn the foreground
jobs View list of tasks running in the background
ps View running processes information
kill Kill a process

Detailed

Suppose now that there is a program called main.py python, and the authority of the program executable

1. &

Running in the background, but the window is closed, the program will terminate

python main.py &

2. nohup

1. On the basis, before the command plusnohupCan be achieved not hang up the running

nohup python main.py &

Here appeared the following tips, do not ignore it, hit Enter

#nohup:忽略输入并将stderr重定向到stdout
nohup: ignoring input and redirecting stderr to stdout

3. ctrl+z

The foreground of the program into the background and pauses

4. bg

The background tasks to freeze up and running again
Note: id here is to get through the jobs command to view

bg id

5. fg

The background process to the foreground running
Note: id here is to look to get jobs through command

fg id

6. jobs

View tasks running in the background of the current terminal, enter the command directly on the line

jobs

7. ps

View the current process, enter the command directly on the line

ps

The difference between the jobs: jobs can only view the terminal in the current process, ps you can see the process in the other terminal, ps has the following parameters
ps -aux | grep "text.sh" a : (all) displays all processes u: user based format x: All process does not end with distinction

Often using the following format, explanation: e: represents the list of all processes, f: represents the complete output formats, grep hzqtest: represents the filter Filter "python" keyword.

ps -ef |grep python

8. kill

First check process with jobs, get it jobsID, attention is needed in the%

kill -9 %jobsID

Ps process with a view to obtain its PID

kill -9 PID

Thank you very much less Bowen
reference Bowen:
In the process of linux commands and programs running in the background script Daquan
Linux under the program running in the background, view, and turn off background programs running
Linux commands and switch back and forth running
under Linux program running in the background: nohup and &

Published 56 original articles · won praise 70 · views 8902

Guess you like

Origin blog.csdn.net/weixin_44835732/article/details/103870302