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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -