我正在尝试在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" ??? 我错过了什么?
我如何在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.