Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 514
birgit Avatar asked Dec 02 '11 16:12

birgit


People also ask

How do I kill ttyUSB0?

Alternatively, if your fuser command supports it you can use the -k option to kill them. Show activity on this post. sudo lsof /dev/ttyUSB0 worked for me as well, thanks! sudo fuser /dev/ttyUSB0 worked for me, thanks.

What does Dev ttyUSB0 mean?

It is the order that the devices are detected. ttyUSB means "USB serial port adapter" and the "0" (or "1" or whatever) is the device number. ttyUSB0 is the first one found, ttyUSB1 is the second etc.

How do you kill a Minicom process?

You may kill minicom from a script with the command "! killall -9 minicom" without hanging up the line.


1 Answers

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.

like image 151
Diego Torres Milano Avatar answered Sep 18 '22 13:09

Diego Torres Milano