[PATCH v7] linux: use PIDFD_GET_INFO ioctl for pidfd_getpid() if available

Luca Boccassi luca.boccassi@gmail.com
Tue Jan 27 22:53:43 GMT 2026


On Tue, 27 Jan 2026 at 20:39, Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 27/01/26 14:51, luca.boccassi@gmail.com wrote:
> > From: Luca Boccassi <luca.boccassi@gmail.com>
> >
> > Linux v6.13 introduced a new ioctl to query info from a pidfd.
> > The advantage of this vs. parsing /proc/ is that it works even
> > when procfs is not mounted. It's also a single syscall, and doesn't
> > need manual string parsing. Use it when available.
> >
> > Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
> > ---
> > v2: use sys/pidfd.h instead of installed kernel headers
> >
> > v3: add __ASSUME_PIDFD_GET_INFO
> >     use atomics for support cache var
> >
> > v4: drop support cache var
> >
> > v5: drop static helper given it's just the ioctl call now, simplifies the flow
> >
> > v6: map ENOTTY to EBADF to avoid breaking documented behaviour
> >
> > v7: switch from ioctl() to __ioctl()
>
> And now it fails with:
>
> $ misc/tst-pidfd_getpid
> ../sysdeps/unix/sysv/linux/tst-pidfd_getpid.c:103: numeric comparison failure
>    left: 3 (0x3, ESRCH); from: errno
>   right: 66 (0x42); from: EREMOTE
> error: 1 test failures
>
> I don't know how to proper fix with the ioctl, since it does not make any
> distinction whether the process does not exists or if it is an different
> namespace.

I talked with Christian and he says it should be fine to change the
kernel to EREMOTE too, I've just sent him a patch to do so.

Unfortunately it doesn't help with existing kernels though. Is there a
test macro that can be used to check for either/or?


More information about the Libc-alpha mailing list