【发布时间】:2017-10-31 20:46:55
【问题描述】:
这是我现在拥有的当前代码,我想知道如何让它杀死 pid。
import commands, signal
stuid = commands.getoutput("pgrep student")
deaid = commands.getoutput("pgrep daemon")
print stuid
os.kill(stuid, signal.SIGKILL)
print deaid
os.kill(deaid, signal.SIGKILL)
编辑: 所以,最后我只是用os.system让终端运行kill命令,然后把pid放在kill之后。
import commands, os
stuid = commands.getoutput("pgrep student")
deaid = commands.getoutput("pgrep daemon")
print stuid
os.system("kill "+stuid)
print deaid
os.system("kill "+deaid)
总的来说,这是我的最终结果。希望这对未来的人们有所帮助。
【问题讨论】:
-
本机可能有一些方法可以做到这一点,但您可以使用subprocess。
-
你在windows上?
-
@DRPK 不,我在 Mac 上。
标签: python python-2.7 pid