Kill process that raises Device or resource busy: '/dev/ttyUSB0'?

▼魔方 西西 提交于 2019-12-12 08:20:06

问题


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: could not open port /dev/ttyUSB0: [Errno 16] Device or resource busy: '/dev/ttyUSB0'

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?


回答1:


You can use

$ fuser /dev/ttyUSB0

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.



来源:https://stackoverflow.com/questions/8359489/kill-process-that-raises-device-or-resource-busy-dev-ttyusb0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!