Python语言实现获取主机名根据端口杀死进程

WBOY
Release: 2016-06-10 15:05:22
Original
1368 people have browsed it

推荐阅读:使用python检测主机存活端口及检查存活主机

下面给大家分享使用python语言实现获取主机名根据端口杀死进程代码。

ip=os.popen("ifconfig eth0|grep 'inet addr'|awk -F ':' '{print $2}'|awk '{print $1}'")
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)))
Copy after login

下面给大家介绍python语言实现根据pid杀死相应进程,kill_process.py代码如下

#! /usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import signal
def kill(pid):
try:
a = os.kill(pid, signal.SIGKILL)
# a = os.kill(pid, signal.9) # 与上等效
print '已杀死pid为%s的进程, 返回值是:%s' % (pid, a)
except OSError, e:
print '没有如此进程!!!'
if __name__ == '__main__':
kill(8132)
ok, Enjoy it !!!
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!