CAPNG\_SETPID(3) Libcap-ng API CAPNG\_SETPID(3)

# [NAME](#NAME)

capng\_setpid - set working pid

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;cap-ng.h&gt;**

void capng\_setpid(int pid);

# [DESCRIPTION](#DESCRIPTION)

capng\_setpid sets the working pid for capabilities operations. This is useful if you want to get the capabilities of a different process.

# [NOTES](#NOTES)

If your process calls **fork** , then the child process will still have the pid of the parent process stored in libcap-ng's internal data. It is disallowed to do any kind of setcap operations because you would be crossing process boundaries. To correct this, if your program links against pthreads, then libcap-ng will use the **pthread\_atfork** function (as a weak symbol) to reset the pid information to the new process automatically. You are not required to link against pthreads. You can call **capng\_setpid** and adjust the stored pid manually.

# [RETURN VALUE](#RETURN_VALUE)

None.

# [SEE ALSO](#SEE_ALSO)

[**capng\_get\_caps\_process**(3)](/man/os/libcap-ng/capng_get_caps_process.3), [**capabilities**(7)](/man/os/libcap-ng/capabilities.7)

# [AUTHOR](#AUTHOR)

Steve Grubb

March 2026 Red Hat

---

Document: capng_setpid(3) from libcap-ng 0.9.6-r0 (Chainguard OS)
Source: https://github.com/stevegrubb/libcap-ng.git
