crigler / dtach

A simple program that emulates the detach feature of screen
GNU General Public License v2.0
492 stars 50 forks source link

dtach has extremely high CPU usage #1

Closed sethdmoore closed 8 years ago

sethdmoore commented 8 years ago

Hello @crigler,

I'm noticing extremely high CPU usage for essentially idle dtach sessions.

# ps aux | head -n 1 ; ps aux | grep dtach
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1592  0.0  0.0  14220   992 pts/6    S+   23:22   0:00 grep --color=auto dtach
user      4111 42.7  0.0  14868   704 ?        Rs   May05 2177:36 dtach -A /home/user/save/irc zsh
user      4133 39.6  0.0   6288   388 pts/4    R+   May05 2015:43 dtach -A /home/user/save/irc zsh
user      4201  0.0  0.0  14868   700 ?        Ss   May05   0:01 dtach -A /home/user/save/irc zsh
# uptime
 23:23:30 up 45 days, 12:05,  3 users,  load average: 1.95, 1.69, 1.66

Here is what strace shows select, read, write in a tight loop

select(4, [0 3], NULL, NULL, NULL)      = 1 (in [0])
read(0, "\3\rxe\f\f\3", 8)              = 7
write(3, "\0\7\3\rxe\f\f\3\0", 10)      = 10
select(4, [0 3], NULL, NULL, NULL)      = 1 (in [0])
read(0, "\3\rxe\f\f\3", 8)              = 7
write(3, "\0\7\3\rxe\f\f\3\0", 10)      = 10
select(4, [0 3], NULL, NULL, NULL)      = 1 (in [0])
read(0, "\3\rxe\f\f\3", 8)              = 7
write(3, "\0\7\3\rxe\f\f\3\0", 10)      = 10

Here is the process tree

systemd─┬─
        ├─dtach───zsh───dtach
        ├─dtach───zsh───irssi───{gmain}

Here is lsof for the two dtach sessoins


/home/user
/
/usr/bin/dtach
/lib/x86_64-linux-gnu/libnss_files-2.23.so
/lib/x86_64-linux-gnu/libnss_nis-2.23.so
/lib/x86_64-linux-gnu/libnsl-2.23.so
/lib/x86_64-linux-gnu/libnss_compat-2.23.so
/lib/x86_64-linux-gnu/libc-2.23.so
/lib/x86_64-linux-gnu/libutil-2.23.so
/lib/x86_64-linux-gnu/ld-2.23.so
/dev/null
/dev/null
/dev/null
/home/user/save/irc type=STREAM
/dev/ptmx
/home/user/save/irc type=STREAM
/home/user
/
/usr/bin/dtach
/lib/x86_64-linux-gnu/libc-2.23.so
/lib/x86_64-linux-gnu/libutil-2.23.so
/lib/x86_64-linux-gnu/ld-2.23.so
/dev/pts/4
/dev/pts/4
/dev/pts/4
type=STREAM
/home/user
/
/usr/bin/dtach
/lib/x86_64-linux-gnu/libnss_files-2.23.so
/lib/x86_64-linux-gnu/libnss_nis-2.23.so
/lib/x86_64-linux-gnu/libnsl-2.23.so
/lib/x86_64-linux-gnu/libnss_compat-2.23.so
/lib/x86_64-linux-gnu/libc-2.23.so
/lib/x86_64-linux-gnu/libutil-2.23.so
/lib/x86_64-linux-gnu/ld-2.23.so
/dev/null
/dev/null
/dev/null
/home/user/save/irc type=STREAM
/dev/ptmx

Version info...

# apt-cache policy dtach
dtach:
  Installed: 0.8-2.1
  Candidate: 0.8-2.1
  Version table:
 *** 0.8-2.1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status
crigler commented 8 years ago

Your process tree shows dtach───zsh───dtach which looks like dtach created a session using /home/user/save/irc and then started zsh which then started dtach attached to /home/user/save/irc again, creating a loop.

sethdmoore commented 8 years ago

That was the issue! Thank you @crigler!