1 .\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
2 .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH GETTID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
8 gettid \- get thread identification
11 .RI ( libc ", " \-lc )
14 .B #define _GNU_SOURCE
15 .B #include <unistd.h>
17 .B pid_t gettid(void);
21 returns the caller's thread ID (TID).
22 In a single-threaded process, the thread ID
23 is equal to the process ID (PID, as returned by
25 In a multithreaded process, all threads
26 have the same PID, but each one has a unique TID.
27 For further details, see the discussion of
32 On success, returns the thread ID of the calling thread.
34 This call is always successful.
38 system call first appeared on Linux in kernel 2.4.11.
39 Library support was added in glibc 2.30.
40 (Earlier glibc versions did not provide a wrapper for this system call,
41 necessitating the use of
45 is Linux-specific and should not be used in programs that
46 are intended to be portable.
48 The thread ID returned by this call is not the same thing as a
49 POSIX thread ID (i.e., the opaque value returned by
50 .BR pthread_self (3)).
52 In a new thread group created by a
54 call that does not specify the
56 flag (or, equivalently, a new process created by
58 the new process is a thread group leader,
59 and its thread group ID (the value returned by
61 is the same as its thread ID (the value returned by
68 .BR get_robust_list (2),
72 .\" .BR move_pages (2),
73 .\" .BR migrate_pages (2),
74 .BR perf_event_open (2),
75 .\" .BR process_vm_readv (2),
77 .BR sched_setaffinity (2),
78 .BR sched_setparam (2),
79 .BR sched_setscheduler (2),