device /dev/ttyusb0 lock failed: operation not permitted

Viewed 48248

I was playing around with a router earlier this evening using minicom and I must not have closed it cleanly. Here is the error message that I get when I try to open minicom:

device /dev/ttyusb0 lock failed: operation not permitted

I have two questions, 1) how would I go about getting out of this state, and 2) how do I exit minicom cleanly so that I can avoid this happening again.

4 Answers

I ran into a similar issue with using gtkterm from a remote terminal. I had shutdown the terminal without explicitly terminating gtkterm. The result was that subsequent gtkterm sessions gave me the error:

Device /dev/ttyUSB0 is locked.

Checking the process list via ps did not show any gtkterm processes still running.

I corrected this by simply deleting /run/lock/LCK..ttyUSB0. After doing that, gtkterm was able to open ttyUSB0 successfully.

  1. [root@edge-tc lock]# minicom'
  2. Device /dev/ttyUSB0 lock failed: Operation not permitted.'
  3. Solution:'
  4. Check the process which have locked and kill the process'
  5. [root@edge-tc lock]# fuser /dev/ttyUSB0'
  6. /dev/ttyUSB0: 18328
  7. [root@edge-tc lock]# kill -9 18328
  8. [root@edge-tc lock]#'
  9. [root@edge-tc lock]#'
  10. [root@edge-tc lock]# minicom'
  11. Welcome to minicom 2.1'

The canonical way is to use lockdev. This manages the lock files on a per-device basis in /run/lock/lockdev/ (at least under CentOS 7.x).

lockdev <device> can be used without being root, and returns non-zero if the device has already been locked, in which case it can be unlocked with lockdev -u <device>.

This is apparently obsolete these days, but minicom (at least as of version 2.6.2) still uses it.

Related