Skip to content

pstree: do not crash on missing /proc/xxxx directory

Piotr Praszmo requested to merge ppraszmo/psmisc:fix-pstree-race into master

This is a fix for: https://bugs.launchpad.net/bugs/1629839

When a lot of processes is starting and ending, such as in this test case:

#!/bin/bash
for i in $(seq 1 8); do
        for i in $(seq 1 1000); do
                pstree -p $$ > /dev/null
        done &
done

pstree will sometimes fail with:

/proc/25156: No such file or directory

This happens because process is visible when pstree reads /proc/ dir but ends before the contents could be fully read. 8b3113db fixes this for open("/proc/pid/cmdline") by ignoring such processes. This patch does the same for stat("/proc/pid/") calls.

Merge request reports