1
0
Fork 0
mirror of synced 2024-12-22 06:41:07 -05:00

improved _pane_info() accuracy by excluding ssh proxy connections, tee, and only

considering the first child of a process

ps output is sorted by controlling terminal then pid

in case of a cmd1 | cmd2 | cmd3 pipe chain, we only consider the first child of
the parent process, which is cmd1 in the majority of cases

the rare situation when pids wrap around isn't worth additional work

on Linux
  - we sort ps output by lstart in hope precision is enough to make cmd1 always
    appear first even when pids wrap around
  - the more complex solution involves inspecting /proc/<pid>/fd/0 to filter out
    processes being piped to

finally, while lsof was promising, it won't list processes owned by other users
unless run as root
This commit is contained in:
Gregory Pakosz 2021-10-20 22:37:03 +02:00
parent 69f744117a
commit 1ef9b68d80

View file

@ -501,8 +501,8 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# case "$_uname_s" in # case "$_uname_s" in
# *CYGWIN*) # *CYGWIN*)
# ps -al | tail -n +2 | awk -v pane_pid="$pane_pid" -v tty="$pane_tty" ' # ps -al | tail -n +2 | awk -v pane_pid="$pane_pid" -v tty="$pane_tty" '
# ((/ssh/ && !/-W/) || !/ssh/) && $5 == tty { # ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ && $5 == tty {
# user[$1] = $6; parent[$1] = $2; child[$2] = $1 # user[$1] = $6; if (!child[$2]) child[$2] = $1
# } # }
# END { # END {
# pid = pane_pid # pid = pane_pid
@ -516,10 +516,24 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# } # }
# ' # '
# ;; # ;;
# *Linux*)
# ps -t "$pane_tty" --sort=lstart -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" '
# ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ {
# user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
# }
# END {
# pid = pane_pid
# while (child[pid])
# pid = child[pid]
#
# print pid":"user[pid]":"command[pid]
# }
# '
# ;;
# *) # *)
# ps -t "$pane_tty" -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" ' # ps -t "$pane_tty" -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk -v pane_pid="$pane_pid" '
# NR > 1 && ((/ssh/ && !/-W/) || !/ssh/) { # ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ {
# user[$2] = $1; parent[$2] = $3; child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4) # user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
# } # }
# END { # END {
# pid = pane_pid # pid = pane_pid