Skip to content

Add ProcessMonitor for kernel-level process exit detection - #29

Draft
probonopd wants to merge 2 commits into
gnustep:mainfrom
probonopd:kernel-process-monitor
Draft

probonopd wants to merge 2 commits into
gnustep:mainfrom
probonopd:kernel-process-monitor

Conversation

@probonopd

@probonopd probonopd commented Sep 13, 2026 •

Copy link
Copy Markdown

Instant detection of application exits through kernel process notifications:

  • Linux: pidfd_open() + poll(); BSDs: kqueue() with EVFILT_PROC/NOTE_EXIT; other systems fail to build instead of polling
  • Waits on an NSThread of its own and reports exits on the main thread (no blocks, no GCD)
  • The Dock watches the processes of all running application items after every scan and every new window, and scans again as soon as one of them exits

The first version added ProcessMonitor but never used it.

Tested: after killing TextEdit its icon is gone within 0.4 s; without this change it was still there after 0.4 s.

Closes #7

Add ProcessMonitor singleton that uses kernel mechanisms for instant
process exit detection:
- Linux: pidfd_open() + poll() (kernel 5.3+)
- FreeBSD/OpenBSD/NetBSD: kqueue() + EVFILT_PROC + NOTE_EXIT
- Fallback: kill(pid, 0) polling every 500ms

The monitor runs on a dedicated thread and dispatches exit callbacks
to the main thread via performSelectorOnMainThread.

Closes gnustep#7
@probonopd

Copy link
Copy Markdown
Author

Does not work yet:

  • Launch Dock
  • Start Chrome (outside of Dock)
  • Quit Chrome
  • Workspace Dock immediately removes the Chrome icon
  • DockWM only removes Chrome icon after ~3 seconds

The icon of an application that quit stayed in the Dock for seconds, because
ProcessMonitor was added but never used, and it relied on blocks, which GCC
builds lack. It now waits for process exits on a thread of its own with pidfd
on Linux and kqueue on the BSDs and reports them on the main thread, and the
Dock watches the processes of all running application items after every scan
and every new window and scans again as soon as one of them exits.

The process identifiers come from a single walk over the process table, which
the scanner now provides and reuses for its other process queries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Kernel process monitoring (pidfd/kqueue) for instant exit detection

1 participant