Wrapping it up with a bow (the /dev/pts/X thread)
From
Kenny McCormack@21:1/5 to
All on Wed Apr 21 23:54:52 2021
I got this sorted, and it turns out to have been a bug (typo) in one of my Expect scripts - that was causing it to not close the ptmx end of the jobs
that it spawns. It was spawning jobs in a loop and not closing them
properly, so you can guess what the result of that would be.
Anyway, here are the two scripts I wrote to debug this problem:
1) Part1 is a script to find all processes (that I own) that have /dev/ptmx open:
--- Cut Here ---
#!/bin/bash
# Run this with no args
# Note: If you don't have setsort on your system, just remove the
# references to it. setsort will make the pids come out in numerical
# order, but it isn't necessary.
ls -lsa /proc/*/fd 2>/dev/null | gawk -i setsort '
sub(/^\/proc\//,"") { pid=$0+0;next }
/\/dev\/ptmx/ { x[pid] = x[pid] " " $10 }
END { setsort(2);for (i in x) print i,x[i] }
'
--- Cut Here ---
Run this and it will produce a line of output for each process that has /dev/ptms open, like this:
<pid> <fd1> <fd2> ...
2) Part2 is a script to launch gdb on each process found above and display
the pts associated with each fd:
--- Cut Here ---
#!/usr/bin/expect --
# The args to this program are generated by the previous script.
# First arg is a pid, subsequent args are fds that point to /dev/ptmx.
set timeout -1
log_file typescript
spawn gdb -p [lindex $argv 0]
expect {
ptrace: { sleep 1;send q\r;expect;exit 1 }
"(gdb)"
}
for {set