Using python as a background service under linux

1. Start the background service
without writing a shell script, call python directly:
nohup python Run_service.py loop=1 >dispatch.nohup 2>&1 & # where loop=1 is a parameter, you need to parse sys.argv in python; the middle > is used for redirection and can be omitted; the last & means Non-blocking operation, no other commands can be executed if not used
logout #Remember this sentence is essential, otherwise the service may still be killed


2. View python related services
ps -ef | grep python

Some of the results are as follows:



3. Stop the service
kill -9 6523 #where 6523 is the process number queried by the ps command, -9 forcibly stops

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326352399&siteId=291194637