Python语言实现获取主机名根据端口杀死进程
作者:浮云飘飘 时间:2023-07-01 10:05:58
推荐阅读:使用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)))
下面给大家介绍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 !!!
标签:python,主机名,杀死,进程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mysql一对多关联查询分页错误问题的解决方法
2024-01-28 05:18:44
update.where无索引导致MySQL死锁问题解决
2024-01-28 01:21:25
![](https://img.aspxhome.com/file/2023/4/112894_0s.png)
[翻译]JavaScript中对象的层次与继承
2008-12-31 13:36:00
![](https://img.aspxhome.com/file/UploadPic/200812/31/cc-2-73s.png)
新手该如何学python怎么学好python?
2022-06-20 07:33:27
Golang中Interface接口的三个特性
2024-04-23 09:35:46
SQL中的开窗函数详解可代替聚合函数使用
2024-01-20 08:03:24
![](https://img.aspxhome.com/file/2023/7/86877_0s.png)
python 30行代码实现蚂蚁森林自动偷能量
2021-07-20 03:04:28
![](https://img.aspxhome.com/file/2023/6/125196_0s.gif)
在matplotlib的图中设置中文标签的方法
2023-10-10 07:17:53
![](https://img.aspxhome.com/file/2023/3/65873_0s.jpg)
Python面向对象之Web静态服务器
2021-09-24 07:32:25
![](https://img.aspxhome.com/file/2023/5/99015_0s.jpg)
Python中ROC曲线绘制
2023-05-28 16:38:15
![](https://img.aspxhome.com/file/2023/8/97358_0s.jpg)
保姆级python教程写个贪吃蛇大冒险
2022-06-23 17:12:39
![](https://img.aspxhome.com/file/2023/1/127631_0s.png)
详解用Python爬虫获取百度企业信用中企业基本信息
2022-07-27 18:49:52
![](https://img.aspxhome.com/file/2023/6/65416_0s.jpg)
python字典操作实例详解
2021-05-21 08:22:24
运用python去除图片水印
2021-05-06 10:54:20
![](https://img.aspxhome.com/file/2023/8/95278_0s.png)
python3.6环境安装+pip环境配置教程图文详解
2022-02-07 11:28:36
![](https://img.aspxhome.com/file/2023/6/135426_0s.jpg)
MySQL 中这么多索引该怎么选择
2024-01-17 12:58:54
Mysql分区表的管理与维护
2024-01-17 09:22:09
Go代码检查的推荐工具及使用详解
2024-05-09 15:00:11
使用python爬取微博数据打造一颗“心”
2022-05-28 22:30:09
![](https://img.aspxhome.com/file/2023/3/103653_0s.png)
Anaconda+vscode+pytorch环境搭建过程详解
2022-04-06 01:37:19
![](https://img.aspxhome.com/file/2023/3/67363_0s.png)