杀死导致设备或资源繁忙的进程:'/dev/ttyUSB0'? [英] Kill process that raises Device or resource busy: '/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屋!