1 .\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
2 .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
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 .TH GETTID 2 2019-03-06 "Linux" "Linux Programmer's Manual"
28 gettid \- get thread identification
31 .B #include <sys/types.h>
33 .B pid_t gettid(void);
37 returns the caller's thread ID (TID).
38 In a single-threaded process, the thread ID
39 is equal to the process ID (PID, as returned by
41 In a multithreaded process, all threads
42 have the same PID, but each one has a unique TID.
43 For further details, see the discussion of
48 On success, returns the thread ID of the calling thread.
50 This call is always successful.
54 system call first appeared on Linux in kernel 2.4.11.
55 Library support was added in glibc 2.30.
56 (Earlier glibc versions did not provide a wrapper for this system call,
57 .\" FIXME . See http://sourceware.org/bugzilla/show_bug.cgi?id=6399
58 .\" "gettid() should have a wrapper"
59 necessitating the use of
63 is Linux-specific and should not be used in programs that
64 are intended to be portable.
66 The thread ID returned by this call is not the same thing as a
67 POSIX thread ID (i.e., the opaque value returned by
68 .BR pthread_self (3)).
70 In a new thread group created by a
72 call that does not specify the
74 flag (or, equivalently, a new process created by
76 the new process is a thread group leader,
77 and its thread group ID (the value returned by
79 is the same as its thread ID (the value returned by
87 .BR get_robust_list (2),
90 .\" .BR move_pages (2),
91 .\" .BR migrate_pages (2),
92 .BR perf_event_open (2),
93 .\" .BR process_vm_readv (2),
95 .BR sched_setaffinity (2),
96 .BR sched_setparam (2),
97 .BR sched_setscheduler (2),