本文介绍了如何用 Python 杀死 Linux 进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 2 个功能自动从串口捕获日志:
I want to automate capturing logs from serial port with 2 functions:
1) 触发开始捕获
2) 触发停止
乍一看
def start_capture_output():
file = '/home/test/Desktop/log.txt'
os.system('touch %s' % file)
os.system('chmod +rwx %s' % file)
os.system('cat </dev/ttyUSB0>%s' % file)
它可以工作,但我想知道如何在不手动按 Ctrl+C 的情况下停止此过程
and it works, but I wonder how to stop this process without manually pressing Ctrl+C
推荐答案
如果你用
child = subprocess.Popen("command")
然后你可以打电话
child.terminate()
child.kill()
- [0] https://docs.python.org/2/library/subprocess.html#subprocess.Popen
- [1] https://docs.python.org/2/library/subprocess.html#popen-objects
这篇关于如何用 Python 杀死 Linux 进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!