用python語言實現根據pid殺死相應進程
kill_process.py代碼如下
代碼如下復制代碼
#! /usr/bin/python
# -*- coding: utf-8 -*-
importos
importsys
importsignal
defkill(pid):
try:
a=os.kill(pid, signal.SIGKILL)
# a = os.kill(pid, signal.9) # 與上等效
print'已殺死pid為%s的進程, 返回值是:%s'%(pid, a)
exceptOSError, e:
print'沒有如此進程!!!'
if__name__=='__main__':
kill(8132)
ok, Enjoy it !!!