Fuser vs lsof to check files in use

fuserlsof

I've been getting some suggestions on how to figure out why my serial port is busy. Specifically, when I try to start gammu-smsd, it refuses to start on /dev/ttyS0 because it says that port is busy:

sudo /etc/init.d/gammu-smsd start
Sep 30 16:16:51 porkypig gammu-smsd[25355]: Starting phone communication...
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [Gammu            - 1.26.1 built 21:46:06 Nov 24 2009 using GCC 4.4]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [Connection       - "at115200"]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [Connection index - 0]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [Model type       - ""]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [Device           - "/dev/ttyS0"]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [Runing on        - Linux, kernel 2.6.32-42-server (#95-Ubuntu SMP Wed Jul 25 16:10:49 UTC 2012)]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: [System error     - open in serial_open, 16, "Device or resource busy"]
Sep 30 16:16:51 porkypig gammu-smsd[25355]: gammu: Init:GSM_TryGetModel failed with error DEVICEOPENERROR[2]: Error opening device. Unknown, busy or no permissions.
Sep 30 16:16:51 porkypig gammu-smsd[25355]: Can't open device (Error opening device. Unknown, busy or no permissions.:2)
Sep 30 16:16:51 porkypig gammu-smsd[25355]: Using PGSQL service
Sep 30 16:16:51 porkypig gammu-smsd[25355]: Disconnecting from PostgreSQL

I used two different commands. Both of them find different processes culpable. First I try fuser:

fuser -m -u /dev/ttyS0 
/dev/ttyS0:          21624(guarddoggps)
cd /proc/21624
cat status
Name:   dropbox
State:  S (sleeping)
Tgid:   21624
Pid:    21624
PPid:   1
TracerPid:  0
Uid:    1001    1001    1001    1001
Gid:    1001    1001    1001    1001
FDSize: 64
Groups: 5 27 1001 5004 
VmPeak:   873732 kB
VmSize:   806040 kB
VmLck:         0 kB
VmHWM:    207668 kB
VmRSS:    131864 kB
VmData:   547820 kB
VmStk:       160 kB
VmExe:      3524 kB
VmLib:     29660 kB
VmPTE:      1244 kB
Threads:    21
SigQ:   0/16382
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000001001000
SigCgt: 00000001800004c8
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: ffffffffffffffff
Cpus_allowed:   ff
Cpus_allowed_list:  0-7
Mems_allowed:   00000000,00000001
Mems_allowed_list:  0
voluntary_ctxt_switches:    202
nonvoluntary_ctxt_switches: 1

So fuser says dropbox is using it.

Then I use lsof:

sudo lsof | grep ttyS0
screen    23520        root    6u      CHR               4,64         0t0       1421 /dev/ttyS0

lsof says screen (rather than dropbox) is using it.

So which of these programs (dropbox or screen) is really causing gammu-smsd to refuse to start because of the resourcing being "busy"?

Best Answer

The short answer is: screen.

The slightly longer answer is that the -m flag to fuser tells it to list everything using the mountpoint. Depending on your setup, that probably means all of /dev, but it could also be /. Clearly not what you intended. You'll get a very long list if you do fuser -vm /dev/ttyS0, over 60 lines on my system.

Take off the -m and it'll probably give you the same answer as lsof did.

Related Question