Blame man2/tkill.2

Packit 7cfc04
.\" Copyright (C) 2008 Michael Kerrisk <tmk.manpages@gmail.com>
Packit 7cfc04
.\" and Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" 2004-05-31, added tgkill, ahu, aeb
Packit 7cfc04
.\" 2008-01-15 mtk -- rewrote DESCRIPTION
Packit 7cfc04
.\"
Packit 7cfc04
.TH TKILL 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
tkill, tgkill \- send a signal to a thread
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.BI "int tkill(int " tid ", int " sig );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int tgkill(int " tgid ", int " tid ", int " sig );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There are no glibc wrappers for these system calls; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR tgkill ()
Packit 7cfc04
sends the signal
Packit 7cfc04
.I sig
Packit 7cfc04
to the thread with the thread ID
Packit 7cfc04
.I tid
Packit 7cfc04
in the thread group
Packit 7cfc04
.IR tgid .
Packit 7cfc04
(By contrast,
Packit 7cfc04
.BR kill (2)
Packit 7cfc04
can be used to send a signal only to a process (i.e., thread group)
Packit 7cfc04
as a whole, and the signal will be delivered to an arbitrary
Packit 7cfc04
thread within that process.)
Packit 7cfc04
.PP
Packit 7cfc04
.BR tkill ()
Packit 7cfc04
is an obsolete predecessor to
Packit 7cfc04
.BR tgkill ().
Packit 7cfc04
It allows only the target thread ID to be specified,
Packit 7cfc04
which may result in the wrong thread being signaled if a thread
Packit 7cfc04
terminates and its thread ID is recycled.
Packit 7cfc04
Avoid using this system call.
Packit 7cfc04
.\" FIXME Maybe say something about the following:
Packit 7cfc04
.\" http://sourceware.org/bugzilla/show_bug.cgi?id=12889
Packit 7cfc04
.\"
Packit 7cfc04
.\" Quoting Rich Felker <bugdal@aerifal.cx>:
Packit 7cfc04
.\"
Packit 7cfc04
.\" There is a race condition in pthread_kill: it is possible that,
Packit 7cfc04
.\" between the time pthread_kill reads the pid/tid from the target
Packit 7cfc04
.\" thread descriptor and the time it makes the tgkill syscall,
Packit 7cfc04
.\" the target thread terminates and the same tid gets assigned
Packit 7cfc04
.\" to a new thread in the same process.
Packit 7cfc04
.\"
Packit 7cfc04
.\" (The tgkill syscall was designed to eliminate a similar race
Packit 7cfc04
.\" condition in tkill, but it only succeeded in eliminating races
Packit 7cfc04
.\" where the tid gets reused in a different process, and does not
Packit 7cfc04
.\" help if the same tid gets assigned to a new thread in the
Packit 7cfc04
.\" same process.)
Packit 7cfc04
.\"
Packit 7cfc04
.\" The only solution I can see is to introduce a mutex that ensures
Packit 7cfc04
.\" that a thread cannot exit while pthread_kill is being called on it.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Note that in most real-world situations, like almost all race
Packit 7cfc04
.\" conditions, this one will be extremely rare. To make it
Packit 7cfc04
.\" measurable, one could exhaust all but 1-2 available pid values,
Packit 7cfc04
.\" possibly by lowering the max pid parameter in /proc, forcing
Packit 7cfc04
.\" the same tid to be reused rapidly.
Packit 7cfc04
.PP
Packit 7cfc04
These are the raw system call interfaces, meant for internal
Packit 7cfc04
thread library use.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, zero is returned.
Packit 7cfc04
On error, \-1 is returned, and \fIerrno\fP
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
An invalid thread ID, thread group ID, or signal was specified.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
Permission denied.
Packit 7cfc04
For the required permissions, see
Packit 7cfc04
.BR kill (2).
Packit 7cfc04
.TP
Packit 7cfc04
.B ESRCH
Packit 7cfc04
No process with the specified thread ID (and thread group ID) exists.
Packit 7cfc04
.TP
Packit 7cfc04
.B EAGAIN
Packit 7cfc04
The
Packit 7cfc04
.B RLIMIT_SIGPENDING
Packit 7cfc04
resource limit was reached and
Packit 7cfc04
.I sig
Packit 7cfc04
is a real-time signal.
Packit 7cfc04
.TP
Packit 7cfc04
.B EAGAIN
Packit 7cfc04
Insufficient kernel memory was available and
Packit 7cfc04
.I sig
Packit 7cfc04
is a real-time signal.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
.BR tkill ()
Packit 7cfc04
is supported since Linux 2.4.19 / 2.5.4.
Packit 7cfc04
.BR tgkill ()
Packit 7cfc04
was added in Linux 2.5.75.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR tkill ()
Packit 7cfc04
and
Packit 7cfc04
.BR tgkill ()
Packit 7cfc04
are Linux-specific and should not be used
Packit 7cfc04
in programs that are intended to be portable.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
See the description of
Packit 7cfc04
.B CLONE_THREAD
Packit 7cfc04
in
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
for an explanation of thread groups.
Packit 7cfc04
.PP
Packit 7cfc04
Glibc does not provide wrappers for these system calls; call them using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR clone (2),
Packit 7cfc04
.BR gettid (2),
Packit 7cfc04
.BR kill (2),
Packit 7cfc04
.BR rt_sigqueueinfo (2)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.