def sig_test (sig_handler_type, fork_type, child_output):
print 'Testing with:'
print '\tsig_handler_type:', sig_handler_type
print '\tfork_type:', fork_type
print '\tchild_output:', child_output
if sig_handler_type == 'SIG_IGN':
signal.signal (signal.SIGCHLD, signal.SIG_IGN)
else:
signal.signal (signal.SIGCHLD, signal_handler)
pid = -1
fd = -1
if fork_type == 'ptyfork':
pid, fd = pty.fork()
else:
pid = os.fork()
if pid == 0:
if child_output == 'yes':
os.write (sys.stdout.fileno(), 'This is a test.\nThis is a test.')
time.sleep(10000)
#print 'Sending SIGKILL to child pid:', pid
time.sleep(2)
os.kill (pid, signal.SIGKILL)
#print 'Entering to sleep...'
try:
time.sleep(2)
except:
pass
try:
os.kill(pid, 0)
print '\tChild is alive. This is ambiguous because it may be a Zombie.'
except OSError as e:
print '\tChild appears to be dead.'
# print str(e)
print
评论列表
文章目录