The python program in centos runs in the background

Use this command (see explanation to make changes to your own commands)

nohup python3 -u main.py > test.log 2>&1 &

explain:

Before operating, first enter the directory of the project

  • nohup is not specified to run in the background, but this nohup is to let the program run forever, it has nothing to do with the front and back (this does not need to be changed)

  • python3 This is the corresponding python command, python generally corresponds to python2, so I will use python3 (generally python2 has an error reporting problem with newline characters on windows)

  • "-u" indicates that the cache is not enabled, and the print information is output to the log file in real time (if you do not add -u, the log file will not refresh the information of the print function in the code in real time)

  • main.py This is the main program of the project, which can be changed to the program you want to run

  • > test.log This closing bracket is to put your output log into the later test.log log file (you can first create a test.log file in the current directory)

  • 2>&1 This 2 indicates the error message output when an error occurs >& This indicates redirection 1 indicates standard output, so the combination is to redirect the error message to standard output

  • & This means running in the background

In general, it is possible to use nohup to run permanently and also to run in the background, so it is to run permanently in the background.

Guess you like

Origin blog.csdn.net/weixin_56170314/article/details/128794844