dalance / procs

A modern replacement for ps written in Rust
MIT License
5.16k stars 118 forks source link

[Feature Request] Add ability to filter out processes from output via regexp and/or parent status #463

Open vvuk opened 1 year ago

vvuk commented 1 year ago

Many times I want to basically do ps -ef | grep foo and get a specific foo's pid. However, sometimes foo actually spawns a million child processes, and I really only care about some specific ones where "some" might be the primary parent process, but might also be a subset of child processes. So, two features:

  1. when run with some keywords to search, only show processes whose parent does not match those keywords. For example:
% procs -t Edge
        PID   User     │ TTY CPU MEM CPU Time │ Command                                                                                                 >
                       │     [%] [%]          │                                                                                                         >
 ├┬──── 11101 vladimir │     0.0 1.1 00:00:07 │ /Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge                                          >
 │├──── 11109 vladimir │     0.0 0.3 00:00:07 │ /Applications/Microsoft Edge.app/Contents/Frameworks/Microsoft Edge Framework.framework/Versions/112.0.1>
 │├──── 11110 vladimir │     0.0 0.3 00:00:02 │ /Applications/Microsoft Edge.app/Contents/Frameworks/Microsoft Edge Framework.framework/Versions/112.0.1>
 │├──── 11112 vladimir │     0.0 0.1 00:00:00 │ /Applications/Microsoft Edge.app/Contents/Frameworks/Microsoft Edge Framework.framework/Versions/112.0.1>
 │├──── 11123 vladimir │     0.0 0.1 00:00:00 │ /Applications/Microsoft Edge.app/Contents/Frameworks/Microsoft Edge Framework.framework/Versions/112.0.1>
 │├──── 11127 vladimir │     0.0 0.2 00:00:00 │ /Applications/Microsoft Edge.app/Contents/Frameworks/Microsoft Edge Framework.framework/Versions/112.0.1>
 ...
 └───── 11103 vladimir │     0.0 0.0 00:00:00 │ /Applications/Microsoft Edge.app/Contents/Frameworks/Microsoft Edge Framework.framework/Versions/112.0.1722.34/Helpers/msedge_crashpad_handler --monitor-self-annotation=ptype=crashpad-handler --database=/Users/vladimir/Library/Application Support/Microsoft Edge/Crashpad --annotation=IsOfficialBuild=1 --annotation=channel= --annotation=exe=Microsoft Edge --annotation=plat=OS X --annotation=prod=Microsoft Edge_Mac --annotation=ver=112.0.1722.34 --handshake-fd=5

with the new option, should only show process 11101 and 11103 (because 11103 is not a child of 11101, unlike all the other framework processes).

  1. a --exclude that takes a regexp argument, that filters out processes whose command lines match the regex. In the above example, adding --filter-out handshake-fd would also filter out process 11103, because it contains "handshake-fd".

While we're at it, could make the default keyword search a regex as well!

vvuk commented 1 year ago

Forgot to mention -- for some reason setting display.show_children_in_tree to false doesn't hide the Edge children above.

luckman212 commented 1 year ago

@vvuk Nice feature request. I came here looking for help on simple fixed string exclusion, which I think is possible in the current version 0.14. For example, to list bash but not -bash. Do you know if this is possible?