进程间通信之类的,用得着,
可以自定义接到信息之后的动作。
file1.py
#!/usr/bin/env python# -*- coding: utf-8 -*-import osimport signalfrom time import sleepdef onsignal_term(a, b): print("Get SIGTERM signal")signal.signal(signal.SIGTERM, onsignal_term)def onsignal_usr1(a, b): print("Get SIGUSR1 signal")signal.signal(signal.SIGUSR1, onsignal_usr1)while 1: print("My process id is: ", os.getpid()) sleep(10)
file2.py
import osimport signalfrom time import sleepwhile 1: os.kill(25334, signal.SIGTERM) os.kill(25334, signal.SIGUSR1) sleep(3)