Last active
September 10, 2015 06:22
-
-
Save praveenkumar/e290baff4c4321a4cd3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import time | |
import os | |
from subprocess import check_output, Popen, CalledProcessError | |
def get_pid(name): | |
return check_output(["pidof",name]) | |
def handler(signum, frame): | |
print "signal handler called with signal %s" % signum | |
pid = int(get_pid('gedit').strip()) | |
os.kill(pid, signal.SIGKILL) | |
signal.signal(signal.SIGALRM, handler) | |
signal.alarm(5) | |
try: | |
check_output('gedit', shell=True) | |
except CalledProcessError as e: | |
print "Process Exit" | |
signal.alarm(0) | |
print "Exit from Gedit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment