OSDN Git Service

Update perkamon to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / tkill.2
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 2014-12-31 "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(int " tid ", int " sig );
35 .sp
36 .BI "int tgkill(int " tgid ", int " tid ", int " sig );
37 .fi
38
39 .IR Note :
40 There are no glibc wrappers for these system calls; see NOTES.
41 .SH DESCRIPTION
42 .BR tgkill ()
43 sends the signal
44 .I sig
45 to the thread with the thread ID
46 .I tid
47 in the thread group
48 .IR tgid .
49 (By contrast,
50 .BR kill (2)
51 can be used to send a signal only to a process (i.e., thread group)
52 as a whole, and the signal will be delivered to an arbitrary
53 thread within that process.)
54
55 .BR tkill ()
56 is an obsolete predecessor to
57 .BR tgkill ().
58 It allows only the target thread ID to be specified,
59 which may result in the wrong thread being signaled if a thread
60 terminates and its thread ID is recycled.
61 Avoid using this system call.
62 .\" FIXME Maybe say something about the following:
63 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=12889
64 .\"     Rich Felker <bugdal@aerifal.cx>
65 .\"     There is a race condition in pthread_kill: it is possible that,
66 .\"     between the time pthread_kill reads the pid/tid from the target
67 .\"     thread descriptor and the time it makes the tgkill syscall,
68 .\"     the target thread terminates and the same tid gets assigned
69 .\"     to a new thread in the same process.
70 .\"
71 .\"     (The tgkill syscall was designed to eliminate a similar race
72 .\"     condition in tkill, but it only succeeded in eliminating races
73 .\"     where the tid gets reused in a different process, and does not
74 .\"     help if the same tid gets assigned to a new thread in the
75 .\"     same process.)
76 .\"
77 .\"     The only solution I can see is to introduce a mutex that ensures
78 .\"     that a thread cannot exit while pthread_kill is being called on it.
79 .\"
80 .\"     Note that in most real-world situations, like almost all race
81 .\"     conditions, this one will be extremely rare. To make it
82 .\"     measurable, one could exhaust all but 1-2 available pid values,
83 .\"     possibly by lowering the max pid parameter in /proc, forcing
84 .\"     the same tid to be reused rapidly.
85
86 These are the raw system call interfaces, meant for internal
87 thread library use.
88 .SH RETURN VALUE
89 On success, zero is returned.
90 On error, \-1 is returned, and \fIerrno\fP
91 is set appropriately.
92 .SH ERRORS
93 .TP
94 .B EINVAL
95 An invalid thread ID, thread group ID, or signal was specified.
96 .TP
97 .B EPERM
98 Permission denied.
99 For the required permissions, see
100 .BR kill (2).
101 .TP
102 .B ESRCH
103 No process with the specified thread ID (and thread group ID) exists.
104 .SH VERSIONS
105 .BR tkill ()
106 is supported since Linux 2.4.19 / 2.5.4.
107 .BR tgkill ()
108 was added in Linux 2.5.75.
109 .SH CONFORMING TO
110 .BR tkill ()
111 and
112 .BR tgkill ()
113 are Linux-specific and should not be used
114 in programs that are intended to be portable.
115 .SH NOTES
116 See the description of
117 .B CLONE_THREAD
118 in
119 .BR clone (2)
120 for an explanation of thread groups.
121
122 Glibc does not provide wrappers for these system calls; call them using
123 .BR syscall (2).
124 .SH SEE ALSO
125 .BR clone (2),
126 .BR gettid (2),
127 .BR kill (2),
128 .BR rt_sigqueueinfo (2)
129 .SH COLOPHON
130 This page is part of release 3.78 of the Linux
131 .I man-pages
132 project.
133 A description of the project,
134 information about reporting bugs,
135 and the latest version of this page,
136 can be found at
137 \%http://www.kernel.org/doc/man\-pages/.