Skip to content

Instantly share code, notes, and snippets.

@praveenkumar
Last active September 10, 2015 06:22
Show Gist options
  • Save praveenkumar/e290baff4c4321a4cd3e to your computer and use it in GitHub Desktop.
Save praveenkumar/e290baff4c4321a4cd3e to your computer and use it in GitHub Desktop.
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