相关疑难解决方法(0)

如何使用pid从Python终止进程?

我正在尝试在python中编写一些简短的脚本,这将在子进程中启动另一个python代码,如果尚未启动,则终止终端和应用程序(Linux).

所以它看起来像:

#!/usr/bin/python
from subprocess import Popen

text_file = open(".proc", "rb")
dat = text_file.read()
text_file.close()

def do(dat):

    text_file = open(".proc", "w")
    p = None

    if dat == "x" :

        p = Popen('python StripCore.py', shell=True)
        text_file.write( str( p.pid ) )

    else :
        text_file.write( "x" )

        p = # Assign process by pid / pid from int( dat )
        p.terminate()

    text_file.close()

do( dat )
Run Code Online (Sandbox Code Playgroud)

应用程序从文件".proc"读取的pid命名过程缺乏知识的问题.另一个问题是解释器说名为dat的字符串不等于"x" ??? 我错过了什么?

python linux terminal process

38
推荐指数
1
解决办法
9万
查看次数

如何在Windows中杀死子进程python

我如何在Windows上杀死进程?

我正在开始这个过程

    self.p = Process(target=self.GameInitialize, args=(testProcess,))
    self.p.start()
Run Code Online (Sandbox Code Playgroud)

我试过了

self.p.kill()
self.p.terminate()
os.kill(self.p.pid, -1)
os.killpg(self.p.pid, signal.SIGTERM)  # Send the signal to all the process groups
Run Code Online (Sandbox Code Playgroud)

错误

Process Object has no Attribute kill
Process Object has no Attribute terminate
Access Denied
Run Code Online (Sandbox Code Playgroud)

我不能用 .join.

python

5
推荐指数
3
解决办法
6231
查看次数

标签 统计

python ×2

linux ×1

process ×1

terminal ×1