blob: 0a7d5f89ca86b60594450b3f6cb764b8110ed8ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#!/usr/bin/env python
import signal
import os
import time
def signal_handler (signum, frame):
print 'Signal handler called with signal:', signum
print 'signal.SIGCHLD=', signal.SIGKILL
# Create a child process for us to kill.
pid = os.fork()
if pid == 0:
time.sleep(10000)
#signal.signal (signal.SIGCHLD, signal.SIG_IGN)
signal.signal (signal.SIGCHLD, signal_handler)
print 'Sending SIGKILL to child pid:', pid
os.kill (pid, signal.SIGKILL)
# SIGCHLD should interrupt sleep.
# Note that this is a race.
# It is possible that the signal handler will get called
# before we try to sleep, but this has not happened yet.
# But in that case we can only tell by order of printed output.
interrupted = 0
try:
time.sleep(10)
except:
print 'sleep was interrupted by signal.'
interrupted = 1
if not interrupted:
print 'ERROR. Signal did not interrupt sleep.'
else:
print 'Signal interrupted sleep. This is good.'
# Let's see if the process is alive.
try:
os.kill(pid, 0)
print 'Child is alive. This is ambiguous because it may be a Zombie.'
except OSError as e:
print 'Child appears to be dead.'
|