Python父进程退出后,子进程自动退出的办法

PR_SET_PDEATHSIG (since Linux 2.1.57)
              Set the parent process death signal of the calling process to arg2
              (either a signal value in the range 1..maxsig, or 0 to clear).  This is
              the signal that the calling process will get when its parent dies.
              This value is cleared for the child of a fork(2).
 
import ctypes 

libc = ctypes.CDLL('libc.so.6')  

pid = os.fork() 
if pid == 0:  
    libc.prctl(1, 15)  
    # something in child

elif pid > 0:
    # something in child

libc.prctl(1, 15) 是起作用的语句。
 
转自 http://xiaoxia.org/2012/03/05/prctl/