杀死引发设备或资源繁忙的进程:'/dev/ttyUSB0'? [英] Kill process that raises Device or resource busy: '/dev/ttyUSB0'?

查看:37
本文介绍了杀死引发设备或资源繁忙的进程:'/dev/ttyUSB0'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下 Python 代码连接到我的 Arduino 板.

I connect to my Arduino board with the following Python code.

device=glob.glob("/dev/ttyUSB*")[0]
time.sleep(1)
arduino = serial.Serial(device, 115200, timeout=5)

它通常有效,但在重启后必须以某种方式访问​​电路板,给我错误

It generally works, but somehow some other process must be accessing the board after reboot giving me the error

serial.serialutil.SerialException: 无法打开端口/dev/ttyUSB0: [Errno 16] 设备或​​资源繁忙:'/dev/ttyUSB0'

serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 16] Device or resource busy: '/dev/ttyUSB0'

拔出和重新插入USB插头时,我可以正常执行Python代码,没有出现错误.如何避免任何其他进程阻塞端口?我如何找出此错误的原因?

When unplugging and replugging the USB-plug I can execute the Python code normally, without the error occuring. How can I avoid any other process blocking the port? And how do I find out the reason for this error?

推荐答案

可以使用

$ fuser /dev/ttyUSB0

列出使用该文件的进程的 PID.或者,如果您的 fuser 命令支持它,您可以使用 -k 选项来杀死它们.

to list the PIDs of the processes using the file. Alternatively, if your fuser command supports it you can use the -k option to kill them.

这篇关于杀死引发设备或资源繁忙的进程:'/dev/ttyUSB0'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆