0

I operate on a shared linux server. It is common practice for team members to open up a few tmux sessions and run some long running commands and then disconnect their ssh session. Eventually the processes they kick off finish, but they may not reconnect for another week or two.

We want to sometimes reset said linux server, but we want to check if there are any running processes/programs/commands still running in any of the tmux sessions that are currently open. Short of attaching to each tmux session and cycling through each window, how do I check which tmux sessions still have running processes/commands, and better yet, see what those commands still being run are?

If there is a way to do this thats multiplexer agnostic (such as it works with both tmux and screen) that would be even better.

n00b
  • 933

2 Answers2

1

If you don't mind a human being needed to parse the results,

ps -auxf | grep "tmux\|screen" -A 5

works pretty well. Passing -xf to ps lists child processes in a tree-like fashion below their parents, and grepping for tmux/screen/etc with a few lines of context enabled (in this example using -A(fter) 5) shows you pretty much everything you need to know.

Louis
  • 31
0

To grep tmux PIDs you can use;

ps aux | grep tmux | grep -v grep | awk '{print $2}' 

To get a tree of active child processes, swap out < PID > in the following command;

ps --forest $(ps -e --no-header -o pid,ppid|awk -vp=<PID>'function r(s){print s;s=a[s];while(s){sub(",","",s);t=s;sub(",.*","",t);sub("[0-9]+","",s);r(t)}}{a[$2]=a[$2]","$1}END{r(p)}')

For a less detailed listing, you can use pstree

pstree -h <PID>
n00b
  • 933