pstop icon indicating copy to clipboard operation
pstop copied to clipboard

feature request: add support for wsl processes

Open Turgon-Aran-Gondolin opened this issue 2 months ago • 3 comments

It would be useful to add support for displaying processes running inside WSL/WSL2.

Currently, WSL resource usage is visible from Windows, but individual Linux processes are not exposed in the process list. This makes it difficult to tell which WSL process is actually consuming CPU or memory.

Ideally, WSL processes could appear alongside Windows processes, with at least:

  • Process name / command
  • PID
  • WSL distribution/An indication that the process belongs to WSL
  • CPU usage
  • Memory usage
  • User

If integrating them directly into the normal process tree is difficult, a separate WSL process section or an optional WSL view would also work well.

This would make the tool much more useful as a Windows htop-style system monitor, especially for users who use WSL heavily.

Turgon-Aran-Gondolin avatar Sep 07 '26 04:09 Turgon-Aran-Gondolin

Hi @Turgon-Aran-Gondolin, thanks for the well-structured request. This was the biggest gap for anyone living in WSL, and you laid out exactly the columns that matter.

Implemented in c9004da: a new WSL tab

Press Tab past GPU (or click it in the tab bar) and you get every Linux process from every running WSL/WSL2 distribution:

  Main   I/O   Net   GPU   WSL
Distro       PID    USER     S CPU%▼ MEM%  RES    THR TIME+     Command
Ubuntu-22.04     42 gj       R 150.0  12.5   977M   8   1:01:01 node server.js --port 3000
Ubuntu-22.04     57 root     I   0.0   0.0     0B   1   0:00.00 [kworker/u8:1]

That covers your list: name/command, PID, distribution, CPU, memory (both MEM% of the distro's RAM and RES), and user, plus state, thread count and TIME+. Sorting works like the other tabs (F6, </>, I, or click a column header), p toggles full paths, and F9 sends the chosen signal (SIGTERM/SIGKILL/SIGHUP/SIGINT/SIGQUIT) to the selected process via kill inside its distro.

I went with a separate tab rather than merging into the Windows tree, as you suggested might be acceptable. Linux PIDs collide with Windows PIDs and have no meaningful parent in the Windows tree, so a dedicated view is cleaner.

How it works under the hood

  • Distros come from wsl.exe --list --running --quiet (its UTF-16 output is decoded properly).
  • For each distro, a small POSIX sh + awk script is piped over stdin to wsl.exe -d <distro> -- sh. It reads /proc/<pid>/stat, /proc/<pid>/status and /etc/passwd in a single awk process (no per-process forks) plus one ps call for full command lines. No dependencies beyond sh, awk and ps, so it works on Ubuntu/Debian/Fedora/openSUSE and on busybox-based distros like Alpine or the Docker Desktop ones.
  • CPU% is a real delta of utime+stime between samples, like htop on Linux (100% = one core busy), keyed by (distro, PID, start time) so a recycled PID never inherits stale counters. The first sighting of a process shows its lifetime average until the second sample lands.
  • Sampling runs on a background thread that is only active while the WSL tab is visible. wsl.exe round-trips take a few hundred ms and can hang badly on a broken install, so every call has a 10 s timeout and the sampler backs off to a 15 s retry when WSL is unavailable. The tab tells you what's going on ("No running WSL distributions", "WSL is not available: ...") instead of sitting blank. If you never open the tab, nothing runs.

Verification, and one honest caveat

Tests cover the UTF-16 decoding, parsing of captured Ubuntu 22.04 /proc output with CPU delta maths, PID recycling, TIME+ formatting, a full-frame render of the tab, and the live wsl.exe path. I also ran the /proc reader script under a real sh/awk against an emulated /proc to confirm field positions and the ps fallback.

The caveat: WSL is broken on my dev machine right now (Wsl/CallMsi/Install/REGDB_E_CLASSNOTREG), which was actually useful for hardening the timeout path, but it means I haven't yet watched the tab against a live Ubuntu instance end to end. If you can build from master (cargo build --release) and open the WSL tab, I'd really appreciate a quick "works" / "here's what I see". I'll leave this open until then and cut the release right after.

psmux avatar Sep 23 '26 08:09 psmux

Hi @psmux , sry I was super busy last month, and hadn't got a chance to look at Github. Here's what it looks like on my end. It seems to be working. Let me know if there's anything else you need.

Image

Turgon-Aran-Gondolin avatar Oct 08 '26 05:10 Turgon-Aran-Gondolin

Thanks so much for testing it @Turgon-Aran-Gondolin, and no worries about the delay. Your screenshot was exactly what I needed.

The WSL tab was already on master when you tried it. I also tested it again against a live Ubuntu distro: a busy loop showed up at 98.5% CPU, state R, with its full command line.

It is now available in v0.5.5: https://github.com/psmux/pstop/releases/tag/v0.5.5

psmux avatar Nov 07 '26 20:11 psmux