Commit graph

10 commits

Author SHA1 Message Date
Zhizhen He
fea2fff082 Avoid caching helper PIDs for launch wrappers
A user launch wrapper can start a persistent helper before the command. Use a lone, unmatched child for the current lookup and cache the child only once its command line matches the launch arguments.
2026-11-18 12:04:49 +08:00
Kovid Goyal
8133effda3
Cleanup previous PR
A wrapper that runs the command as a child, rather than exec-ing it, can
run other children before, after or alongside it, such as a script that
runs some setup commands first. Re-check that the cached child of a
wrapper is still its live child, so that root_pid does not get stuck on
an exited helper, or on the command after it exits while the wrapper
keeps running. When a wrapper has several children, prefer the one
running the wrapped command, and only cache the choice if it is certain.

Match wrappers specified by name when their argv[0] is the path they
were found at, as is the case when run by the hold kitten, and wrappers
specified by path only by that exact path.

Compare the wrapper argv and the script arguments with empty arguments
dropped, as cmdline_of_pid() does on Linux, in one place, so that
binary wrappers with empty arguments are also matched.

Add tests for wrappers that run other commands, that exec after being
seen, with prefix and empty arguments, run via the hold kitten, and for
matches_cmdline() and runs_command().
2026-11-18 08:21:55 +05:30
Zhizhen He
8fe8b2bfeb
Fix root PID tracking for script launch wrappers
Recognize the original script invocation after the interpreter arguments so root_pid can follow wrappers that run the command as a child.
2026-11-18 07:50:46 +05:30
Kovid Goyal
f8556bbf8d
Fix #10858 2026-11-14 08:16:53 +05:30
Kovid Goyal
6815b7a8a4
More useful error message for flaky test failure 2026-10-26 06:50:34 +05:30
Kovid Goyal
4a99b367c5
Use the root process, not kitty's wrapper, for a window's process info
The cmdline, environment and working directory of a window, as reported
by kitten @ ls, used for matching windows and saved in the window state,
now come from the root process, skipping over wrappers kitty inserts
such as /usr/bin/login on macOS. Previously on macOS these described the
login process. Cache the resolved root process so that this is cheap.
2026-10-23 01:17:33 +05:30
Kovid Goyal
b6df55d1c6
Fix process tree memory accounting missing children of non-main threads
On Linux /proc/<pid>/task/<pid>/children only lists the children
created by the main thread, so children created by other threads of
multi-threaded programs were missed. Read the children lists of all
threads instead. On kernels without per thread children lists, build
the full parent to children map once instead of finding nothing. Also
avoid computing the descendants twice when the cgroup contains
processes outside the tree.
2026-10-23 01:13:42 +05:30
Kovid Goyal
42f241da28
Fix launch --cwd=root using the wrong process
When the root process was not in the foreground, cwd=root used the cwd
of the foreground process instead of the root process. Also skip over
wrapper processes that kitty itself inserts, such as /usr/bin/login on
macOS and the run-shell kitten used for --hold, using their first child
as the root process instead. Previously on macOS cwd=root always
resolved to the home directory, the cwd of login.

On Linux, read the children of all threads of a process, since
multi-threaded programs such as kitten can create children from any
thread.

Make cwd_of_child and modify_argv_for_launch_with_cwd use the same
logic for deciding when the reported cwd applies to cwd=root.

Closes #10720
2026-10-23 01:07:04 +05:30
Kovid Goyal
9d33c21131
... 2026-08-05 05:32:57 +05:30
Kovid Goyal
5cd6072570
Function to get memory used by processes rooted at pid 2026-07-29 13:25:51 +05:30