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.


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.

| improve this answer | |
  • I ended up using a combination of "ps --forest" and "pstree" so I wouldnt have to deal with grep, but you headed me down the right path, so +1 – n00b Jun 12 '19 at 21:54

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>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.