1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
.\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
.\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH gettid 2 2024-05-02 "Linux man-pages (unreleased)"
.SH NAME
gettid \- get thread identification
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.B #define _GNU_SOURCE
.B #include <unistd.h>
.P
.B pid_t gettid(void);
.fi
.SH DESCRIPTION
.BR gettid ()
returns the caller's thread ID (TID).
In a single-threaded process, the thread ID
is equal to the process ID (PID, as returned by
.BR getpid (2)).
In a multithreaded process, all threads
have the same PID, but each one has a unique TID.
For further details, see the discussion of
.B CLONE_THREAD
in
.BR clone (2).
.SH RETURN VALUE
On success, returns the thread ID of the calling thread.
.SH ERRORS
This call is always successful.
.SH STANDARDS
Linux.
.SH HISTORY
Linux 2.4.11,
glibc 2.30.
.SH NOTES
The thread ID returned by this call is not the same thing as a
POSIX thread ID (i.e., the opaque value returned by
.BR pthread_self (3)).
.P
In a new thread group created by a
.BR clone (2)
call that does not specify the
.B CLONE_THREAD
flag (or, equivalently, a new process created by
.BR fork (2)),
the new process is a thread group leader,
and its thread group ID (the value returned by
.BR getpid (2))
is the same as its thread ID (the value returned by
.BR gettid ()).
.SH SEE ALSO
.BR capget (2),
.BR clone (2),
.BR fcntl (2),
.BR fork (2),
.BR get_robust_list (2),
.BR getpid (2),
.\" .BR kcmp (2),
.BR ioprio_set (2),
.\" .BR move_pages (2),
.\" .BR migrate_pages (2),
.BR perf_event_open (2),
.\" .BR process_vm_readv (2),
.\" .BR ptrace (2),
.BR sched_setaffinity (2),
.BR sched_setparam (2),
.BR sched_setscheduler (2),
.BR tgkill (2),
.BR timer_create (2)
|