htop-dev / htop

htop - an interactive process viewer
https://htop.dev/
GNU General Public License v2.0
6.33k stars 430 forks source link

Self-reference starting point: will enable showing only subtree of tmux in which htop is running #704

Open poetaman opened 3 years ago

poetaman commented 3 years ago

Terminal multiplexers like tmux are powerful, and are used in conjunction with htop to track the status of all processes running under same tmux.

Following is an example screenshot from htop running in a pane of tmux: Screen Shot 2021-07-21 at 11 35 45 AM

What is being asked?

Provide a switch --selftree=LEVEL. This will only print the process tree starting at LEVEL parent processes above htop. So to achieve printing the tree like in the screenshot above, user would start htop in a tmux pane with command like:

>>htop --selftree=2

BenBE commented 3 years ago

This seems similar to #76 …

poetaman commented 3 years ago

@BenBE Yep on the output side, but input interface is different. Not all programs that htop can be run in (tmux, vim, nvim, etc) provide their root PID to be able to filter. So it would be good to have this input interface, and given that htop already draws trees, it could get to know its ancestor nodes at different LEVEL's.

Also while the user can run htop each time to manually find the ancestor level of interest and its PID, its nevertheless a manual process. Given how useful it is to know what is going in the whole program from which htop is launched, it will become a frequently used feature IMO as none other utility provides this ability.

BenBE commented 3 years ago

You mean like some basic syntax like SELF~2 to get the tmux process in the screenshot above? Certainly doable, but still requires the overall filtering infrastructure for #76 to be implemented, after that it's a quick step to allow the user to tap into this function via the CLI.

poetaman commented 3 years ago

@BenBE Yep, syntax doesn't matter, but you got it right :) I was typing this while you commented:

If not a new switch, this can perhaps be a new filter category. This also intersects with the feature request in comment https://github.com/htop-dev/htop/issues/76#issuecomment-746840168, where user wants to provide a PID. In this feature, the PID will be found by htop by finding its own ppid (parent pid) LEVEL number of times. It doesn't matter what the syntax is. You can decide what's the best option for your codebase.

poetaman commented 3 years ago

This will also enable running htop in a terminal window under programs like vim/neovim to be able to see what activity is going on inside those editors...