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:
+18
-4
@@ -501,8 +501,8 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
|
||||
# case "$_uname_s" in
|
||||
# *CYGWIN*)
|
||||
# ps -al | tail -n +2 | awk -v pane_pid="$pane_pid" -v tty="$pane_tty" '
|
||||
# ((/ssh/ && !/-W/) || !/ssh/) && $5 == tty {
|
||||
# user[$1] = $6; parent[$1] = $2; child[$2] = $1
|
||||
# ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ && $5 == tty {
|
||||
# user[$1] = $6; if (!child[$2]) child[$2] = $1
|
||||
# }
|
||||
# END {
|
||||
# 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" '
|
||||
# NR > 1 && ((/ssh/ && !/-W/) || !/ssh/) {
|
||||
# user[$2] = $1; parent[$2] = $3; child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
|
||||
# ((/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
|
||||
|
||||
Reference in New Issue
Block a user