python program linux background running

Linux programs run in the background

linux semaphore

  • SIGINT
    • Ctrl + C sends sigint semaphore
  • SIGHUP
    • Close session to send sighup semaphore

start command

program

test.py

# encoding=utf8
import time
if __name__ == "__main__":
    i = 0
    while True:
        print i
        time.sleep(1)
  • python test.py &

    • output to terminal
    • Receive SIGHUP semaphore to kill process
    • Does not respond to SIGINT semaphore
  • nohup python test.py

    • output to nohup.out
    • Receiving a SIGINT semaphore kills the process
    • Does not respond to SIGHUP semaphores
  • nohup python test.py &

    • no output
    • Does not respond to SIGHUP semaphores
    • Does not respond to SIGINT semaphore
    • End the process with the kill command

Guess you like

Origin blog.csdn.net/chinesesexyman/article/details/105513626