分类: Python/Ruby
2013-12-18 22:40:26
#!/usr/bin/env python
#coding:utf8
import subprocess
import signal
#信号处理函数,打印一段话
def sigint_handler(signum,frame):
print "In signal SIGINT handler"
#注册信号。
signal.signal(signal.SIGINT,sigint_handler)
ping = subprocess.Popen(args="ping -c 4 )
ping.wait()
print ping.pid
print ping.returncode
PING (115.239.210.26) 56(84) bytes of data.
64 bytes from 115.239.210.26: icmp_req=1 ttl=127 time=33.7 ms
64 bytes from 115.239.210.26: icmp_req=2 ttl=127 time=42.6 ms
^CIn signal SIGINT handler
64 bytes from 115.239.210.26: icmp_req=3 ttl=127 time=38.4 ms
--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 10215ms
rtt min/avg/max/mdev = 33.721/38.270/42.680/3.665 ms
2881
-2