1 .\" Copyright (c) 2019 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH PIDFD_SEND_SIGNAL 2 2019-09-19 "Linux" "Linux Programmer's Manual"
27 pidfd_send_signal \- send a signal to a process specified by a file descriptor
30 .B "#include <signal.h>"
32 .BI "int pidfd_send_signal(int " pidfd ", int " sig ", siginfo_t *" info ,
33 .BI " unsigned int " flags );
37 .BR pidfd_send_signal ()
38 system call sends the signal
40 to the target process referred to by
42 a PID file descriptor that refers to a process.
43 .\" See the very detailed commit message for kernel commit
44 .\" 3eb39f47934f9d5a3027fe00d906a45fe3a15fad
50 buffer, that buffer should be populated as described in
51 .BR rt_sigqueueinfo (2).
55 argument is a NULL pointer,
56 this is equivalent to specifying a pointer to a
58 buffer whose fields match the values that are
59 implicitly supplied when a signal is sent using
65 is set to the signal number;
75 is set to the caller's PID; and
78 is set to the caller's real user ID.
81 The calling process must either be in the same PID namespace as the
82 process referred to by
84 or be in an ancestor of that namespace.
88 argument is reserved for future use;
89 currently, this argument must be specified as 0.
92 .BR pidfd_send_signal ()
94 On error, \-1 is returned and
96 is set to indicate the cause of the error.
101 is not a valid PID file descriptor.
105 is not a valid signal.
108 The calling process is not in a PID namespace from which it can
109 send a signal to the target process.
116 The calling process does not have permission to send the signal
117 to the target process.
121 doesn't refer to the calling process, and
124 .BR rt_sigqueueinfo (2)).
127 The target process does not exist
128 (i.e., it has terminated and been waited on).
130 .BR pidfd_send_signal ()
131 first appeared in Linux 5.1.
133 .BR pidfd_send_signal ()
136 Currently, there is no glibc wrapper for this system call; call it using
139 .SS PID file descriptors
142 argument is a PID file descriptor,
143 a file descriptor that refers to process.
144 Such a file descriptor can be obtained in any of the following ways:
154 via the PID file descriptor that is returned by a call to
163 .BR pidfd_send_signal ()
164 system call allows the avoidance of race conditions that occur
165 when using traditional interfaces (such as
168 The problem is that the traditional interfaces specify the target process
169 via a process ID (PID),
170 with the result that the sender may accidentally send a signal to
171 the wrong process if the originally intended target process
172 has terminated and its PID has been recycled for another process.
174 a PID file descriptor is a stable reference to a specific process;
175 if that process terminates,
176 .BR pidfd_send_signal ()
189 #include <sys/syscall.h>
191 #ifndef __NR_pidfd_send_signal
192 #define __NR_pidfd_send_signal 424
196 pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
199 return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
203 main(int argc, char *argv[])
210 fprintf(stderr, "Usage: %s <pid> <signal>\en", argv[0]);
216 /* Obtain a PID file descriptor by opening the /proc/PID directory
217 of the target process */
219 snprintf(path, sizeof(path), "/proc/%s", argv[1]);
221 pidfd = open(path, O_RDONLY);
227 /* Populate a \(aqsiginfo_t\(aq structure for use with
228 pidfd_send_signal() */
230 memset(&info, 0, sizeof(info));
231 info.si_code = SI_QUEUE;
234 info.si_uid = getuid();
235 info.si_pid = getpid();
236 info.si_value.sival_int = 1234;
238 /* Send the signal */
240 if (pidfd_send_signal(pidfd, sig, &info, 0) == \-1) {
241 perror("pidfd_send_signal");
252 .BR rt_sigqueueinfo (2),
254 .BR pid_namespaces (7),