程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How do I use PID to terminate a process from Python- How to terminate process from Python using pid?

編輯:Python

problem :

I'm trying to write some short script in python which would start another python code in subprocess if is not already started else terminate terminal & app (Linux). I'm trying to python Write some short scripts in , If not already started , It will start another in the child process python Code , Otherwise, terminate the terminal and application (Linux).

So it looks like: So it looks like :

#!/usr/bin/pythonfrom subprocess import Popentext_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 )

Have problem of lacking knowledge to name proces by pid which app reads from file ".proc" . There is a lack of access through the application from the file “.proc” Read the pid The problem of naming process knowledge .The other problem is that interpreter says that string named dat is not equal to "x" ??? Another problem is that the interpreter says it's called dat Of The string is not equal to "x" ???What I've missed ? What I missed ?


Solution :

Reference resources : https://stackoom.com/en/question/1CvOy

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved