Recommended reading: Using Python to detect host survival ports and check for surviving hosts
Let's share with you the Python language implementation gets the hostname to kill the process code based on the port.
Ip=os.popen ("Ifconfig eth0|grep ' inet addr ' |awk-f ': ' {print $} ' |awk ' {print $} ') Ip=ip. Read (). Strip () Pid=os.popen ("Netstat-anp|grep 8998 |awk ' {print $7} '). Read (). Split ('/') [0]os.popen (' kill-9 {0} '). Format (int (PID)))
below to introduce the Python language implementation according to the PID kill the corresponding process, kill_process.py code as follows
#! /usr/bin/python#-*-coding:utf-8-*-import osimport sysimport signaldef Kill (PID): try:a = Os.kill (PID, signal. SIGKILL) # a = Os.kill (PID, SIGNAL.9) # with the equivalent print ' killed PID for the process of%s, the return value is:%s '% (PID, a) except OSError, E:print ' no such process!!! ' if __name__ = = ' __main__ ': Kill (8132) OK, Enjoy it!!!