I have 3 USB webcams and 3 Arduino's plugged into the same computer. On startup, they are labeled /dev/videoN (N goes from 0 to 2) and /dev/ttyACMN (N goes from 0 to 2). So far, so good.

The problem is when something goes wrong with one of the devices (ie, the Arduino, its IDE, or the video capture program crashes). Then the device is assigned a new device file (like /dev/video3 or /dev/ttyACM3). I would like to keep the same device file instead.

Plugging and unplugging the device does not help; neither does closing all the programs that should be interacting with it. If the problem occurs a second time, then yet another device file is created with an even higher number.

It's as if a handle to the old device file is floating around somewhere, and preventing the same device file from being reused. However, the original device file itself (say, /dev/ttyACM0) no longer exists, or at least does not show up in a directory listing.

The only way I have figured out to fix this problem is to reboot. Instead of rebooting, is there a way to purge any lingering references to the original device file so that it can be reused? Or, to force a total purge of all USB devices and renumber from scratch?


I figured this out. Basically, when the device name is not reused, it means some process is still using the old device name. I thought I was closing everything, but there were some processes still running even after I closed all the visible windows.

Here's how to find the process that is using the device name:

lsof | grep /dev/ttyACM0

Then, once I kill that process and power cycle the device, the device name is reused as desired.

| improve this answer | |

You can avoid much headache when you have to kill a process every time by writing udev rules to add symlinks for those devices.

So whenever the device disappear, the symlink will die with it. Then if you replug your device it creates new node with incremented number ex:/dev/ttyACM1. However, the link gets created in the same path.

See How to distinguish between identical USB-to-serial adapters?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.