Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/x86_64-linux-gnu/sys/pidfd.h
1 /* Wrapper for file descriptors that refers to a process functions. 2 Copyright (C) 2022-2026 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 The GNU C Library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, see 17 <https://www.gnu.org/licenses/>. */ 18 19 #ifndef _PIDFD_H 20 21 #include <fcntl.h> 22 #include <bits/types/siginfo_t.h> 23 #include <sys/ioctl.h> 24 25 #define PIDFD_NONBLOCK O_NONBLOCK 26 #define PIDFD_THREAD O_EXCL 27 28 #define PIDFD_SIGNAL_THREAD (1UL << 0) 29 #define PIDFD_SIGNAL_THREAD_GROUP (1UL << 1) 30 #define PIDFD_SIGNAL_PROCESS_GROUP (1UL << 2) 31 32 #define PIDFS_IOCTL_MAGIC 0xFF 33 34 #define PIDFD_GET_CGROUP_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 1) 35 #define PIDFD_GET_IPC_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 2) 36 #define PIDFD_GET_MNT_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 3) 37 #define PIDFD_GET_NET_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 4) 38 #define PIDFD_GET_PID_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 5) 39 #define PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 6) 40 #define PIDFD_GET_TIME_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 7) 41 #define PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 8) 42 #define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9) 43 #define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10) 44 45 /* Sentinels to avoid allocating a file descriptor to refer to own process. */ 46 #define PIDFD_SELF_THREAD -10000 47 #define PIDFD_SELF_THREAD_GROUP -10001 48 #define PIDFD_SELF PIDFD_SELF_THREAD 49 #define PIDFD_SELF_PROCESS PIDFD_SELF_THREAD_GROUP 50 51 52 /* Flags for pidfd_info. */ 53 54 /* Always returned, even if not requested */ 55 #define PIDFD_INFO_PID (1UL << 0) 56 /* Always returned, even if not requested */ 57 #define PIDFD_INFO_CREDS (1UL << 1) 58 /* Always returned if available, even if not requested */ 59 #define PIDFD_INFO_CGROUPID (1UL << 2) 60 /* Only returned if requested. */ 61 #define PIDFD_INFO_EXIT (1UL << 3) 62 /* Only returned if requested. */ 63 #define PIDFD_INFO_COREDUMP (1UL << 4) 64 65 66 /* Value for coredump_mask in pidfd_info. Only valid if PIDFD_INFO_COREDUMP 67 is set in mask. */ 68 69 /* Did crash and... */ 70 #define PIDFD_COREDUMPED (1U << 0) 71 /* coredumping generation was skipped. */ 72 #define PIDFD_COREDUMP_SKIP (1U << 1) 73 /* coredump was done as the user. */ 74 #define PIDFD_COREDUMP_USER (1U << 2) 75 /* coredump was done as root. */ 76 #define PIDFD_COREDUMP_ROOT (1U << 3) 77 78 struct pidfd_info 79 { 80 __uint64_t mask; 81 __uint64_t cgroupid; 82 __uint32_t pid; 83 __uint32_t tgid; 84 __uint32_t ppid; 85 __uint32_t ruid; 86 __uint32_t rgid; 87 __uint32_t euid; 88 __uint32_t egid; 89 __uint32_t suid; 90 __uint32_t sgid; 91 __uint32_t fsuid; 92 __uint32_t fsgid; 93 __int32_t exit_code; 94 __uint32_t coredump_mask; 95 __uint32_t __spare1; 96 }; 97 98 /* sizeof first published struct */ 99 #define PIDFD_INFO_SIZE_VER0 64 100 101 #define PIDFD_GET_INFO _IOWR(PIDFS_IOCTL_MAGIC, 11, struct pidfd_info) 102 103 /* Returns a file descriptor that refers to the process PID. The 104 close-on-exec is set on the file descriptor. */ 105 extern int pidfd_open (__pid_t __pid, unsigned int __flags) __THROW; 106 107 /* Duplicates an existing file descriptor TARGETFD in the process referred 108 by the PIDFD file descriptor PIDFD. 109 110 The FLAGS argument is reserved for future use, it must be specified 111 as 0. */ 112 extern int pidfd_getfd (int __pidfd, int __targetfd, 113 unsigned int __flags) __THROW; 114 115 /* Sends the signal SIG to the target process referred by the PIDFD. If 116 INFO points to a siginfo_t buffer, it will be populated. */ 117 extern int pidfd_send_signal (int __pidfd, int __sig, siginfo_t *__info, 118 unsigned int __flags) __THROW; 119 120 /* Query the process ID (PID) from process descriptor FD. Return the PID 121 or -1 in case of an error. */ 122 extern pid_t pidfd_getpid (int __fd) __THROW; 123 124 #endif /* _PIDFD_H */