进程间通信之类的,用得着,
可以自定义接到信息之后的动作。
file1.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import signal from time import sleep def 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 os import signal from time import sleep while 1: os.kill(25334, signal.SIGTERM) os.kill(25334, signal.SIGUSR1) sleep(3)
时间: 2024-10-03 10:43:01