walles / px

ps, top and pstree for human beings
MIT License
234 stars 9 forks source link
command-line command-line-tool console console-application htop ipc linux macos osx pex pgrep pipe process-monitor ps pstree python python3 terminal top tui

|Linux CI Status| |macOS CI Status|

ps, top and pstree for Human Beings

See below for how to install_.

ptop is what I usually use when Bubblemon_ shows something unexpected is going on.

px I use for figuring out things like "do I still have any Flutter_ processes running in the background"?

pxtree can be used as watch --color pxtree brew to figure out what Homebrew_ is doing.

Output

ptop

If you're coming from htop or some other top variant, here's what to expect from ptop, with explanations below the screenshot:

|ptop screenshot|

pxtree

|pxtree screenshot|

px

Running just px lists all running processes, with the most interesting ones last. Output truncated for brevity.

::

PID COMMAND USERNAME CPU CPUTIME RAM COMMANDLINE 0 kernel root -- -- -- kernel PID 0 273 SandboxHelper _coreaudiod 0% 0.01s 0% /System/Library/Frameworks/AudioToolbox.framework/XPCServices/com.apple.audio.SandboxHelper.xpc/Contents/MacOS/com.apple.audio.SandboxHelper 596 installerdiagd root 0% 0.01s 0% /System/Library/PrivateFrameworks/InstallerDiagnostics.framework/Versions/A/Resources/installerdiagd 983 periodic-wrapper root 0% 0.01s 0% /usr/libexec/periodic-wrapper daily ... 57417 Google Chrome Helper johan 0% 1m03s 2% /Applications/Google Chrome.app/Contents/Versions/70.0.3538.102/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=renderer --field-trial-handle=5536258455526146518,14669732848005555331,131072 --service-pipe-token=7224348701576210538 --lang=sv --metrics-client-id=576E1A60-CA59-34F4-6C0C-57F64BD5F01C --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --num-raster-threads=4 --enable-zero-copy --enable-gpu-memory-buffer-compositor-resources --enable-main-frame-before-activation --service-request-channel-token=7224348701576210538 --renderer-client-id=1119 --no-v8-untrusted-code-mitigations --seatbelt-client=418 14983 studio johan 0% 1h22m 14% /Applications/Android Studio.app/Contents/MacOS/studio 57993 kcm root 0% 0.02s 0% /System/Library/PrivateFrameworks/Heimdal.framework/Helpers/kcm --launchd 57602 Code Helper johan 0% 12.73s 2% /private/var/folders/cg/d7qzk4s13s9c8t49t3txdjpr0000gn/T/AppTranslocation/B5DDDD81-5A91-4961-B18B-20DAB3925EB0/d/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --type=renderer --js-flags=--nolazy --no-sandbox --primordial-pipe-token=570B948A976AACDA8EBB532E5680C83E --lang=sv --app-path=/private/var/folders/cg/d7qzk4s13s9c8t49t3txdjpr0000gn/T/AppTranslocation/B5DDDD81-5A91-4961-B18B-20DAB3925EB0/d/Visual Studio Code.app/Contents/Resources/app --node-integration=true --webview-tag=true --no-sandbox --background-color=#171717 --disable-blink-features=Auxclick --enable-pinch --num-raster-threads=4 --enable-zero-copy --enable-gpu-memory-buffer-compositor-resources --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,34037;0,11,34037;0,12,34037;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,34037;1,11,34037;1,12,34037;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,34037;2,11,34037;2,12,34037;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,34037;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,34037;3,13,3553;3,14,34037;3,15,34037;4,0,3553;4,1,3553;4,2,3553;4,3,3553;4,4,3553;4,5,34037;4,6,3553;4,7,3553;4,8,3553;4,9,3553;4,10,3553;4,11,3553;4,12,34037;4,13,3553;4,14,34037;4,15,34037 --service-request-channel-token=570B948A976AACDA8EBB532E5680C83E --renderer-client-id=110 57996 cat johan 0% 0.0s 0% cat 57745 GradleDaemon johan 0% 32.75s 3% /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java -Xmx1536m -Dfile.encoding=UTF-8 -Duser.country=SE -Duser.language=sv -Duser.variant -cp /Users/johan/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/gradle-4.6/lib/gradle-launcher-4.6.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 4.6

px java

This lists all Java processes. Note how they are presented as their main class (GradleDaemon) rather than as their executable (java). This support is available for many VMs_.

::

PID COMMAND USERNAME CPU CPUTIME RAM COMMANDLINE 57745 GradleDaemon johan 0% 35.09s 3% /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java -Xmx1536m -Dfile.encoding=UTF-8 -Duser.country=SE -Dus

px _coreaudiod

This lists all processes owned by the _coreaudiod user.

::

PID COMMAND USERNAME CPU CPUTIME RAM COMMANDLINE 273 SandboxHelper _coreaudiod 0% 0.01s 0% /System/Library/Frameworks/AudioToolbox.framework/XPCServices/com.apple.audio.SandboxHelper.xpc/Contents/MacOS/com.apple.audio.SandboxHelper 190 DriverHelper _coreaudiod 0% 0.3s 0% /System/Library/Frameworks/CoreAudio.framework/Versions/A/XPCServices/com.apple.audio.DriverHelper.xpc/Contents/MacOS/com.apple.audio.DriverHelper 182 coreaudiod _coreaudiod 0% 11m28s 0% /usr/sbin/coreaudiod

sudo px 80727

This shows detailed info about PID 80727.

::

/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java -Xmx1536M -Dfile.encoding=UTF-8 -Duser.country=SE -Duser.language=sv -Duser.variant -cp /Users/johan/.gradle/wrapper/dists/gradle-3.5-all/7s64ktr9gh78lhv83n6m1hq9u6/gradle-3.5/lib/gradle-launcher-3.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 3.5

kernel(0) root launchd(1) root --> GradleDaemon(80727) johan

31m33s ago GradleDaemon was started, at 2017-06-18T13:47:53+02:00. 7.6% has been its average CPU usage since then, or 2m22s/31m33s

Other processes started close to GradleDaemon(80727): -fish(80678) was started 9.0s before GradleDaemon(80727) iTerm2(80676) was started 9.0s before GradleDaemon(80727) login(80677) was started 9.0s before GradleDaemon(80727) mdworker(80729) was started just after GradleDaemon(80727) mdworker(80776) was started 21.0s after GradleDaemon(80727)

Users logged in when GradleDaemon(80727) started: _mbsetupuser johan

2017-06-18T14:19:26.521988: Now invoking lsof, this can take over a minute on a big system... 2017-06-18T14:19:27.070396: lsof done, proceeding.

Others sharing this process' working directory (/) Working directory too common, never mind.

File descriptors: stdin : [PIPE] (0x17d7619d3ae04819) stdout: [CHR] /dev/null stderr: [CHR] /dev/null

Network connections: [IPv6] :56789 (LISTEN) [IPv6] :62498 (LISTEN)

Inter Process Communication: mDNSResponder(201): [unix] ->0xe32cbd7be6021f1f

For a list of all open files, do "sudo lsof -p 80727", or "sudo watch lsof -p 80727" for a live view.

The IPC data comes from lsof. sudo helps lsof get more detailed information; the command will work without it but might miss some information.

Killing processes

If you want an interactive process killer using px and fzf_, you can make a shell alias out of this:

::

px --sort=cpupercent | fzf --bind 'ctrl-r:reload(px --sort=cpupercent)' --height=20 --no-hscroll --tac --no-sort --header-lines=1 | awk '{print $1}' | xargs kill -9

Type for fuzzy process search, use arrow keys to pick a process, Enter to kill, CTRL-R to refresh the process list.

Or with previews for the currently selected process:

::

px --sort=cpupercent --no-username | fzf --preview='px --color {1}' --bind 'ctrl-r:reload(px --sort=cpupercent --no-username)' --height=20 --no-hscroll --tac --no-sort --header-lines=1 | awk '{print $1}' | xargs kill -9

Installation

On Debian 10 Buster or later, and on Ubuntu 19.04 Disco and later, install using::

sudo apt install px

If you have Homebrew_ on your system (likely on macOS)::

brew install px

On Arch Linux_::

paru -S px_ptop

On other systems, install into /usr/local/bin by copy / pasting this command into a terminal::

curl -Ls https://github.com/walles/px/raw/python/install.sh | bash

Or you can install from Pypi. At least on macOS this can be problematic however, so brew or the above install script is still preferred::

sudo pip install --upgrade pxpx

After installing you should be able to run px, px --help or ptop from the command line. Otherwise please verify that /usr/local/bin is in your $PATH.

To try px without installing it, just download the latest px.pex_, chmod a+x px.pex, then run ./px.pex.

Usage

Just type px or ptop, that's a good start!

To exit ptop, press "q".

Also try px --help to see what else px can do except for just listing all processes.

If you run into problems, try running with the --debug switch, it will print debug logging output after px/ptop is done.

Development

Prerequisites

Building and Running

Note that before editing any code, you need to run tox.sh once to create the px/version.py file.

Note that the build infrastructure here is designed to create a px.pex file that works on "all" machines with Python 3 interpreters (tested on Linux and macOS).

You can also run ./devbin/tox-in-docker.sh, which can be used to run Linux tests on a Mac.

Releasing a new Version

To release a new version, run ./devbin/release.sh and follow instructions.

Performance testing

Keeping this benchmark performant is important to be able to use px on big systems.

To run it in a profiler, install pyinstrument_ and:

Or, to benchmark process listing:

TODO top replacement

TODO iotop replacement

TODO misc

DONE

.. _how to install: #installation .. _Bubblemon: https://walles.github.io/bubblemon/ .. _Flutter: https://flutter.dev .. _Debian 10 Buster: https://wiki.debian.org/DebianBuster .. _Ubuntu 19.04 Disco: https://launchpad.net/ubuntu/disco/ .. _Homebrew: https://brew.sh .. _Arch Linux: https://archlinux.org/ .. _download the latest px.pex: https://github.com/walles/px/releases/latest .. _Unix domain sockets: https://en.wikipedia.org/wiki/Unix_domain_socket .. _This support is available for many VMs: https://github.com/walles/px/blob/python/tests/px_commandline_test.py .. _moar: https://github.com/walles/moar .. _tox: https://pypi.org/project/tox/ .. _pyinstrument: https://github.com/joerick/pyinstrument#installation .. _fzf: https://github.com/junegunn/fzf

.. |Linux CI Status| image:: https://github.com/walles/px/actions/workflows/linux-ci.yml/badge.svg :target: https://github.com/walles/px/actions/workflows/linux-ci.yml?query=branch%3Apython .. |macOS CI Status| image:: https://github.com/walles/px/actions/workflows/macos-ci.yml/badge.svg :target: https://github.com/walles/px/actions/workflows/macos-ci.yml?query=branch%3Apython .. |ptop screenshot| image:: doc/ptop-screenshot.png .. |pxtree screenshot| image:: doc/pxtree-screenshot.png