Skip to content

Fix proc_nice_basic.phpt in a PID namespace - #25856

Open
inode64 wants to merge 1 commit into
php:PHP-8.4from
inode64:fix-proc-nice-pid-namespace
Open

inode64 wants to merge 1 commit into
php:PHP-8.4from
inode64:fix-proc-nice-pid-namespace

Conversation

@inode64

@inode64 inode64 commented Nov 28, 2026

Copy link
Copy Markdown

The description below was drafted with an LLM (Claude Code, Claude Opus 5.5) and reviewed before posting.

proc_nice_basic.phpt compares the niceness that ps -p <getmypid()> reports. In a PID namespace whose /proc still belongs to the parent namespace, getmypid() is a PID of the new namespace and ps looks up an unrelated process of the parent one, or fails with fatal library error, lookup self. This is how Gentoo's Portage runs the test suite (pid-sandbox), and it is easy to reproduce:

$ unshare -Urpf php -r 'echo getmypid(), " | ", shell_exec("ps -p ".getmypid()." -o pid,nice,comm | tail -n 1");'
1 | 1   0 systemd

On Linux the test now reads the niceness with nice(1), which prints the niceness it inherits from the calling process, whatever namespace ps would look in. Other systems keep using ps.

Tested with PHP 8.4.28 on Linux (run-tests.php with TEST_PHP_EXECUTABLE):

normal unshare -Urpf
before PASS FAIL
after PASS PASS

The same change has been carried by the PHP 8.4 and 8.5 ebuilds of our Gentoo overlay: https://github.com/inode64/inode64-overlay/blob/main/dev-lang/php/files/php-8.4-proc-nice-pid-namespace.patch

🤖 Generated with Claude Code

The test compares the niceness that ps reports for getmypid(). In a
PID namespace whose /proc still belongs to the parent namespace, as in
Gentoo's Portage pid-sandbox or "unshare -Urpf", getmypid() is a PID of
the new namespace and ps looks up an unrelated process of the parent
one (PID 1 is the host's init), or fails with "fatal library error,
lookup self", so the test fails.

On Linux, read the niceness with nice(1) instead: a child inherits the
niceness of the calling process, whatever namespace ps would look in.
Other systems keep using ps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N8fTR5F9qkNs7QLgr6V3Ei
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant