7

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"?

2 Answers 2

6

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.

1
  • I killed the screen session and it worked. It was screen all along! Oct 9, 2013 at 21:59
2

When I tried to execute gammu-smsd as a daemon, my syslog (which the daemon writes to) indicated that the /dev/ttyS0 port was currently open and in use.

So in order to figure out what was using it, I initially ran

fuser -m -u /dev/ttyS0 

However, that -m switch gave a deceptive response because as @derobert said it lists everything using the mountpoint.

It was the lsof command the correctly reported the process using the specified port:

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

Now I tried to delete the gnu screen session the clean way:

screen -ls
There is a screen on:
    23520.pts-6.porkypig    (09/30/2013 02:49:47 PM)    (Detached)
1 Socket in /var/run/screen/S-root.
screen -S 21200.pts-1.porkypig -X quit

While that quit the session, the process was still alive:

$ cd /proc/23520
$ head -n 1 status
    screen

and:

     $ ps aux | grep 23520
zsh: correct 'aux' to 'auxv' [nyae]? n
root      5111  0.0  0.0   4348   784 pts/7    S+   16:20   0:00 strace -p 23520
1001      5574  0.0  0.0   7636   920 pts/4    S+   17:51   0:00 grep 23520
root     23520  0.0  0.0  25604  1532 ?        Ss   Sep30   0:00 SCREEN /dev/ttyS0 115200

So i killed the process itself:

# kill 23520
# ps aux | grep 23520
  root      5665  0.0  0.0   7636   916 pts/4    S+   17:54   0:00 grep 23520

And finally the process terminated.

Now I started gammu:

sudo /etc/init.d/gammu-smsd start

And it is running fine:

$ ps aux | grep gammu-smsd
gammu     6042  0.0  0.0  87776  2652 ?        Ss   18:12   0:00 /usr/bin/gammu-smsd --daemon --user gammu --pid /var/run/gammu-smsd.pid
1001      6069  0.0  0.0   7636   912 pts/4    R+   18:13   0:00 grep gammu-smsd

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .