1 .\" Copyright (c) 2019 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH pidfd_send_signal 2 (date) "Linux man-pages (unreleased)"
7 pidfd_send_signal \- send a signal to a process specified by a file descriptor
10 .RI ( libc ", " \-lc )
13 .BR "#include <linux/signal.h>" " /* Definition of " SIG* " constants */"
14 .BR "#include <signal.h>" " /* Definition of " SI_* " constants */"
15 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
16 .B #include <unistd.h>
18 .BI "int syscall(SYS_pidfd_send_signal, int " pidfd ", int " sig ,
19 .BI " siginfo_t *_Nullable " info ", unsigned int " flags );
23 glibc provides no wrapper for
24 .BR pidfd_send_signal (),
25 necessitating the use of
29 .BR pidfd_send_signal ()
30 system call sends the signal
32 to the target process referred to by
34 a PID file descriptor that refers to a process.
35 .\" See the very detailed commit message for kernel commit
36 .\" 3eb39f47934f9d5a3027fe00d906a45fe3a15fad
42 buffer, that buffer should be populated as described in
43 .BR rt_sigqueueinfo (2).
47 argument is a null pointer,
48 this is equivalent to specifying a pointer to a
50 buffer whose fields match the values that are
51 implicitly supplied when a signal is sent using
57 is set to the signal number;
67 is set to the caller's PID; and
70 is set to the caller's real user ID.
73 The calling process must either be in the same PID namespace as the
74 process referred to by
76 or be in an ancestor of that namespace.
80 argument is reserved for future use;
81 currently, this argument must be specified as 0.
84 .BR pidfd_send_signal ()
86 On error, \-1 is returned and
88 is set to indicate the error.
93 is not a valid PID file descriptor.
97 is not a valid signal.
100 The calling process is not in a PID namespace from which it can
101 send a signal to the target process.
108 The calling process does not have permission to send the signal
109 to the target process.
113 doesn't refer to the calling process, and
116 .BR rt_sigqueueinfo (2)).
119 The target process does not exist
120 (i.e., it has terminated and been waited on).
126 .SS PID file descriptors
129 argument is a PID file descriptor,
130 a file descriptor that refers to process.
131 Such a file descriptor can be obtained in any of the following ways:
141 via the PID file descriptor that is returned by a call to
150 .BR pidfd_send_signal ()
151 system call allows the avoidance of race conditions that occur
152 when using traditional interfaces (such as
155 The problem is that the traditional interfaces specify the target process
156 via a process ID (PID),
157 with the result that the sender may accidentally send a signal to
158 the wrong process if the originally intended target process
159 has terminated and its PID has been recycled for another process.
161 a PID file descriptor is a stable reference to a specific process;
162 if that process terminates,
163 .BR pidfd_send_signal ()
167 .\" SRC BEGIN (pidfd_send_signal.c)
176 #include <sys/syscall.h>
180 pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
183 return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
187 main(int argc, char *argv[])
194 fprintf(stderr, "Usage: %s <pid> <signal>\en", argv[0]);
200 /* Obtain a PID file descriptor by opening the /proc/PID directory
201 of the target process. */
203 snprintf(path, sizeof(path), "/proc/%s", argv[1]);
205 pidfd = open(path, O_RDONLY);
211 /* Populate a \[aq]siginfo_t\[aq] structure for use with
212 pidfd_send_signal(). */
214 memset(&info, 0, sizeof(info));
215 info.si_code = SI_QUEUE;
218 info.si_uid = getuid();
219 info.si_pid = getpid();
220 info.si_value.sival_int = 1234;
222 /* Send the signal. */
224 if (pidfd_send_signal(pidfd, sig, &info, 0) == \-1) {
225 perror("pidfd_send_signal");
237 .BR rt_sigqueueinfo (2),
239 .BR pid_namespaces (7),