William Jia
William Jia

Reputation: 1127

device /dev/ttyusb0 lock failed: operation not permitted

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.

Upvotes: 12

Views: 66452

Answers (4)

Popup
Popup

Reputation: 376

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.

Upvotes: 0

Ajun
Ajun

Reputation: 41

  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'

Upvotes: 4

user656698
user656698

Reputation:

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.

Upvotes: 10

Ash
Ash

Reputation: 276

I found I was able to fix the situation on my CentOS box by running minicom -S <device> -o and the do the normal exit key sequence (CTRL-a, x).

In your situation it would have been

sudo minicom -S ttyusb0 -o

This cleared the lock files minicom had placed in /var/lock/

Good luck Ash

Upvotes: 26

Related Questions