signals - How to handle SIGUSR1 in python -


import os   import signal   time import sleep    child=[]  in range(2):     pid = os.fork()     if pid == 0:         child=[]         print 'child start,pid',os.getpid()         break     else:         child.append(pid)  if(child):     def onsig1(a,b):         print 'onsig1->',a      signal.signal(signal.sigchld,onsig1)     signal.signal(signal.sigusr1,onsig1)      try:         print os.getpid(),' start wait...',str(child)         while true:             pid, stat = os.wait()             print '--->',pid,stat     except exception e:         print 'error -->',str(e) else:     def onsig2(a,b):         print 'onsig2->',a     signal.signal(signal.sigusr2,onsig2)     while true:         sleep(10)         print os.getpid(),'say ...' 

12500 start wait... [12501, 12502]
when used 'kill -usr2 12501' , got 'onsig2->12' , 2 child process alive. understand this.
when used 'kill -usr1 12500',i got 'onsig1->10',but father process dead.
don't understand why.

sorry, forgot wrap try block while

while true:     try:         print os.getpid(),' start wait...',str(child)         while true:             pid, stat = os.wait()             print '--->',pid,stat     except exception e:         print 'error -->',str(e) 

Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

formula - R: how to pass in a reference to the variable in glm or lm? -