How to move SimpleSocket server into a background process

前端 未结 2 1876
离开以前
离开以前 2020-12-12 04:04

I have a simple socketServer that works perfectly on the main thread.

#Server PORT
PORT = 8020
#reassign variables
Handler = Server #this is a S         


        
2条回答
  •  情书的邮戳
    2020-12-12 04:35

    Assuming you are running your script on a POSIX operating system and your script is named socket_server.py, you can use nohup like this:

    $ nohup python socket_server.py >> /dev/null 2>&1 &
    

    That will put your script in the background, make it immune to hangups, and you can exit your SSH session. The shell will print out the job number and PID:

    $ [1] 1234
    

    You can stop it later by getting sending a SIGTERM using kill:

    $ kill -SIGTERM 1234
    

提交回复
热议问题