open.2: Make it clearer that an FD is an index into the process's FD table
[man-pages.git] / man2 / tkill.2
bloba6752591beab291bcfbd424642ed90cfc85f3d84
1 .\" Copyright (C) 2008 Michael Kerrisk <tmk.manpages@gmail.com>
2 .\" and Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
3 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" 2004-05-31, added tgkill, ahu, aeb
27 .\" 2008-01-15 mtk -- rewrote DESCRIPTION
28 .\"
29 .TH TKILL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 tkill, tgkill \- send a signal to a thread
32 .SH SYNOPSIS
33 .nf
34 .BI "int tkill(pid_t " tid ", int " sig );
35 .BI "int tgkill(pid_t " tgid ", pid_t " tid ", int " sig );
36 .fi
37 .PP
38 .IR Note :
39 There is no glibc wrapper for
40 .BR tkill ();
41 see NOTES.
42 .SH DESCRIPTION
43 .BR tgkill ()
44 sends the signal
45 .I sig
46 to the thread with the thread ID
47 .I tid
48 in the thread group
49 .IR tgid .
50 (By contrast,
51 .BR kill (2)
52 can be used to send a signal only to a process (i.e., thread group)
53 as a whole, and the signal will be delivered to an arbitrary
54 thread within that process.)
55 .PP
56 .BR tkill ()
57 is an obsolete predecessor to
58 .BR tgkill ().
59 It allows only the target thread ID to be specified,
60 which may result in the wrong thread being signaled if a thread
61 terminates and its thread ID is recycled.
62 Avoid using this system call.
63 .\" FIXME Maybe say something about the following:
64 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=12889
65 .\"
66 .\" Quoting Rich Felker <bugdal@aerifal.cx>:
67 .\"
68 .\" There is a race condition in pthread_kill: it is possible that,
69 .\" between the time pthread_kill reads the pid/tid from the target
70 .\" thread descriptor and the time it makes the tgkill syscall,
71 .\" the target thread terminates and the same tid gets assigned
72 .\" to a new thread in the same process.
73 .\"
74 .\" (The tgkill syscall was designed to eliminate a similar race
75 .\" condition in tkill, but it only succeeded in eliminating races
76 .\" where the tid gets reused in a different process, and does not
77 .\" help if the same tid gets assigned to a new thread in the
78 .\" same process.)
79 .\"
80 .\" The only solution I can see is to introduce a mutex that ensures
81 .\" that a thread cannot exit while pthread_kill is being called on it.
82 .\"
83 .\" Note that in most real-world situations, like almost all race
84 .\" conditions, this one will be extremely rare. To make it
85 .\" measurable, one could exhaust all but 1-2 available pid values,
86 .\" possibly by lowering the max pid parameter in /proc, forcing
87 .\" the same tid to be reused rapidly.
88 .PP
89 These are the raw system call interfaces, meant for internal
90 thread library use.
91 .SH RETURN VALUE
92 On success, zero is returned.
93 On error, \-1 is returned, and \fIerrno\fP
94 is set to indicate the error.
95 .SH ERRORS
96 .TP
97 .B EAGAIN
98 The
99 .B RLIMIT_SIGPENDING
100 resource limit was reached and
101 .I sig
102 is a real-time signal.
104 .B EAGAIN
105 Insufficient kernel memory was available and
106 .I sig
107 is a real-time signal.
109 .B EINVAL
110 An invalid thread ID, thread group ID, or signal was specified.
112 .B EPERM
113 Permission denied.
114 For the required permissions, see
115 .BR kill (2).
117 .B ESRCH
118 No process with the specified thread ID (and thread group ID) exists.
119 .SH VERSIONS
120 .BR tkill ()
121 is supported since Linux 2.4.19 / 2.5.4.
122 .BR tgkill ()
123 was added in Linux 2.5.75.
125 Library support for
126 .BR tgkill ()
127 was added to glibc in version 2.30.
128 .SH CONFORMING TO
129 .BR tkill ()
131 .BR tgkill ()
132 are Linux-specific and should not be used
133 in programs that are intended to be portable.
134 .SH NOTES
135 See the description of
136 .B CLONE_THREAD
138 .BR clone (2)
139 for an explanation of thread groups.
141 Glibc does not provide a wrapper for
142 .BR tkill ();
143 call it using
144 .BR syscall (2).
145 Before glibc 2.30, there was also no wrapper function for
146 .BR tgkill ().
147 .SH SEE ALSO
148 .BR clone (2),
149 .BR gettid (2),
150 .BR kill (2),
151 .BR rt_sigqueueinfo (2)