pidfd_open(2) System Calls Manual pidfd_open(2) pidfd_open - (libc -lc) #include /* SYS_* */ #include int syscall(SYS_pidfd_open, pid_t pid, unsigned int flags); : glibc pidfd_open() syscall(2). pidfd_open() pid. . flags 0 : PIDFD_NONBLOCK ( 5.10) . waitid(2) EAGAIN . PIDFD_THREAD ( 6.9) ( ). pid . pidfd_open() ( ). -1 errno . EINVAL flags . EINVAL pid . EMFILE ( RLIMIT_NOFILE getrlimit(2)). ENFILE . ENODEV . ENOMEM . ESRCH pid . . 5.3. fork(2): pid = fork(); if (pid > 0) { /* If parent */ pidfd = pidfd_open(pid, 0); ... } pidfd_open() PID . : o SIGCHLD SIG_IGN ( sigaction(2)) o SA_NOCLDWAIT SIGCHLD SIG_DFL ( sigaction(2)) o ( wait(2) ). ( PID ) clone(2) CLONE_PIDFD. PID PID pidfd_open() ( clone(2) CLONE_PID) : o pidfd_send_signal(2) PID. o PID poll(2) select(2) epoll(7). (EPOLLIN). (EPOLLHUP). (read(2) EINVAL). PIDFD_THREAD : o PIDFD_THREAD . o PIDFD_THREAD . o PID waitid(2). o pidfd_getfd(2) PID. o PID setns(2) (namespaces) . o PID process_madvise(2) . pidfd_open() PID . /proc/pid. proc(5) (mounted) (pollable) waitid(2). PID PID . poll(2) EPOLLIN. #define _GNU_SOURCE #include #include #include #include #include #include static int pidfd_open(pid_t pid, unsigned int flags) { return syscall(SYS_pidfd_open, pid, flags); } int main(int argc, char *argv[]) { int pidfd, ready; struct pollfd pollfd; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_SUCCESS); } pidfd = pidfd_open(atoi(argv[1]), 0); if (pidfd == -1) { perror("pidfd_open"); exit(EXIT_FAILURE); } pollfd.fd = pidfd; pollfd.events = POLLIN; ready = poll(&pollfd, 1, -1); if (ready == -1) { perror("poll"); exit(EXIT_FAILURE); } printf("Events (%#x): POLLIN is %sset\n", pollfd.revents, (pollfd.revents & POLLIN) ? "" : "not "); close(pidfd); exit(EXIT_SUCCESS); } clone(2), kill(2), pidfd_getfd(2), pidfd_send_signal(2), poll(2), process_madvise(2), select(2), setns(2), waitid(2), epoll(7) 3 . . : . 6.18 8 2026 pidfd_open(2)