Os.pidfd_open missing

os.pidfd_open gives me an AttributeError saying that os does not have an attribute pidfd_open.

I am running a locally built version of python which we distribute with our software. The python version is 3.11 (docs say pidfd_open is new in 3.9) I am running on Ubuntu 24.04 which uses kernel 6.8 (docs say pidfd_open needs at least 5.3).

Does anyone understand why pidfd_open is missing? Or can you suggest any diagnostics I can gather to help diagnose the problem?

Can you see if your kernel does in fact support the syscall? I think the following should test that. If you get errno 38, that would suggest the call is not in your kernel.

import ctypes, os
libc = ctypes.CDLL(None, use_errno=True)
fd = libc.syscall(434, os.getpid(), 0)
if fd >= 0:
    print(f"Success, fd:{fd}")
else:
    print(f"Unsupported, errno: {ctypes.get_errno()}")

Problem solved. I am running Ubuntu 24.04, but some of our customers are running much older distros than that. sys/fd.h in the container used to build python doesn’t have pidfd_open defined, so Python skips it.