1 .\" Copyright (C) 2008 Michael Kerrisk <tmk.manpages@gmail.com>
2 .\" and Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" 2004-05-31, added tgkill, ahu, aeb
27 .\" 2008-01-15 mtk -- rewrote DESCRIPTION
29 .TH TKILL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
31 tkill, tgkill \- send a signal to a thread
34 .BR "#include <signal.h>" " /* Definition of " SIG* " constants */"
35 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
36 .B #include <unistd.h>
38 .BI "int syscall(SYS_tkill, pid_t " tid ", int " sig );
40 .B #include <signal.h>
42 .BI "int tgkill, pid_t " tgid ", pid_t " tid ", int " sig );
46 glibc provides no wrapper for
48 necessitating the use of
54 to the thread with the thread ID
60 can be used to send a signal only to a process (i.e., thread group)
61 as a whole, and the signal will be delivered to an arbitrary
62 thread within that process.)
65 is an obsolete predecessor to
67 It allows only the target thread ID to be specified,
68 which may result in the wrong thread being signaled if a thread
69 terminates and its thread ID is recycled.
70 Avoid using this system call.
71 .\" FIXME Maybe say something about the following:
72 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=12889
74 .\" Quoting Rich Felker <bugdal@aerifal.cx>:
76 .\" There is a race condition in pthread_kill: it is possible that,
77 .\" between the time pthread_kill reads the pid/tid from the target
78 .\" thread descriptor and the time it makes the tgkill syscall,
79 .\" the target thread terminates and the same tid gets assigned
80 .\" to a new thread in the same process.
82 .\" (The tgkill syscall was designed to eliminate a similar race
83 .\" condition in tkill, but it only succeeded in eliminating races
84 .\" where the tid gets reused in a different process, and does not
85 .\" help if the same tid gets assigned to a new thread in the
88 .\" The only solution I can see is to introduce a mutex that ensures
89 .\" that a thread cannot exit while pthread_kill is being called on it.
91 .\" Note that in most real-world situations, like almost all race
92 .\" conditions, this one will be extremely rare. To make it
93 .\" measurable, one could exhaust all but 1-2 available pid values,
94 .\" possibly by lowering the max pid parameter in /proc, forcing
95 .\" the same tid to be reused rapidly.
97 These are the raw system call interfaces, meant for internal
100 On success, zero is returned.
101 On error, \-1 is returned, and \fIerrno\fP
102 is set to indicate the error.
108 resource limit was reached and
110 is a real-time signal.
113 Insufficient kernel memory was available and
115 is a real-time signal.
118 An invalid thread ID, thread group ID, or signal was specified.
122 For the required permissions, see
126 No process with the specified thread ID (and thread group ID) exists.
129 is supported since Linux 2.4.19 / 2.5.4.
131 was added in Linux 2.5.75.
135 was added to glibc in version 2.30.
140 are Linux-specific and should not be used
141 in programs that are intended to be portable.
143 See the description of
147 for an explanation of thread groups.
149 Before glibc 2.30, there was also no wrapper function for
155 .BR rt_sigqueueinfo (2)