1 #!/usr/bin/python 2 3 import os,time 4 from signal import * 5 6 def get_sig(signum,stack): 7 if signum==SIGINT: 8 print "keep..." 9 elif signum==SIGALRM: 10 print "get an alarm" 11 else: 12 print "other signal" 13 14 15 16 alarm(7) 17 signal(SIGINT,get_sig) 18 signal(SIGALRM,get_sig) 19 20 print "my pid is ",os.getpid() 21 22 while True: 23 print "waiting...." 24 time.sleep(2)