Code :
import psutil
import os
import signal
pids = psutil.get_pid_list()
for pid in pids:
if psutil.Process(pid).name == "process_name":
os.kill(pid,signal.SIGHUP)
break
Steps to follow.
2.Use os.kill(pid,sig) command to send out the SIGHUP signal to that process.
1.Get the PID of the process to which you want to send out a SIGHUP signal.
One has to install a package called psutil by the following command.
easy_install psutil
Check out the following links for more details
use psutil.get_pid_list() to get all of the PIDs.
psutil.get_pid_list() works in the following manner.
pids = [int(x) for x in os.listdir('/proc') if x.isdigit()]
return pids
once you get all the PIDs get the PID you are interested by comparing the name of the process.
if psutil.Process(pid).name == "process_name":
2.Use os.kill(pid,sig) command to send out the SIGHUP signal to that process.
os.kill(pid,signal.SIGHUP).
Done :)
I know the method of going through all the PIDs is not a good idea ! but i could not find anything better so .....
Comments
Post a Comment