python 多线程查找进程pid
2013-01-16 14:49
169 查看
import os,time,threading class Message(threading.Thread): def __init__(self,name): threading.Thread.__init__(self) self.name = name def printIt(self): # print 'checking process is : ' + self.num cmd = 'ps -C ' + self.name + ' -o pid,cmd' ret=os.popen(cmd).readlines() if len(ret) < 2: print '[' + self.name + '] process ' + ' process not found' # os.system('top') elif len(ret) >= 2: print '[' + self.name + '] process ' + ret[0].strip()[0:3] + ' is ' + ret[-1].strip()[:-3] else: print "other error" def run(type): thread1 = Message(type[0]) thread2 = Message(type[1]) thread1.printIt() thread2.printIt() if __name__ == '__main__': type=["top","aa"] run(type)
相关文章推荐
- python的多线程、多进程代码示例
- python的多线程与多进程介绍及多进程详解(调用multiprocessing组件)
- Python中的GIL、多进程和多线程
- Python3 多进程和多线程
- Python多线程、异步+多进程爬虫实现代码
- Linux用ps命令查找进程PID再用kill命令终止进程的方法
- python中的多线程和多进程
- 【Python笔记】Python多线程进程如何正确响应Ctrl-C以实现优雅退出
- 根据pid查找进程运行路径
- 多线程-threading和进程VS线程(python 版)
- linux中根据进程的PID值来查找执行文件的及其路径
- Python中单线程、多线程和多进程的效率对比实验
- python 多进程和多线程
- Python多线程和多进程谁更快?
- Python 09--多线程、进程
- Linux用ps命令查找进程PID再用kill命令终止进程的方法
- python queue和多线程的爬虫 与 JoinableQueue和多进程的爬虫
- Python获取系统所有进程PID及进程名称的方法示例
- 查找进程pid号,然后将该进程关闭
- 查找进程对应的PID和对应的端口号