scripts/bash_aliases: tfix
[man-pages.git] / man2 / gettid.2
blob4d924572551c0ea88e85c9a0cc814a94b018f8b3
1 .\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
2 .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
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 .TH GETTID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 gettid \- get thread identification
29 .SH SYNOPSIS
30 .nf
31 .B #define _GNU_SOURCE
32 .B #include <unistd.h>
33 .PP
34 .B pid_t gettid(void);
35 .fi
36 .SH DESCRIPTION
37 .BR gettid ()
38 returns the caller's thread ID (TID).
39 In a single-threaded process, the thread ID
40 is equal to the process ID (PID, as returned by
41 .BR getpid (2)).
42 In a multithreaded process, all threads
43 have the same PID, but each one has a unique TID.
44 For further details, see the discussion of
45 .BR CLONE_THREAD
47 .BR clone (2).
48 .SH RETURN VALUE
49 On success, returns the thread ID of the calling thread.
50 .SH ERRORS
51 This call is always successful.
52 .SH VERSIONS
53 The
54 .BR gettid ()
55 system call first appeared on Linux in kernel 2.4.11.
56 Library support was added in glibc 2.30.
57 (Earlier glibc versions did not provide a wrapper for this system call,
58 necessitating the use of
59 .BR syscall (2).)
60 .SH CONFORMING TO
61 .BR gettid ()
62 is Linux-specific and should not be used in programs that
63 are intended to be portable.
64 .SH NOTES
65 The thread ID returned by this call is not the same thing as a
66 POSIX thread ID (i.e., the opaque value returned by
67 .BR pthread_self (3)).
68 .PP
69 In a new thread group created by a
70 .BR clone (2)
71 call that does not specify the
72 .BR CLONE_THREAD
73 flag (or, equivalently, a new process created by
74 .BR fork (2)),
75 the new process is a thread group leader,
76 and its thread group ID (the value returned by
77 .BR getpid (2))
78 is the same as its thread ID (the value returned by
79 .BR gettid ()).
80 .SH SEE ALSO
81 .BR capget (2),
82 .BR clone (2),
83 .BR fcntl (2),
84 .BR fork (2),
85 .BR get_robust_list (2),
86 .BR getpid (2),
87 .\" .BR kcmp (2),
88 .BR ioprio_set (2),
89 .\" .BR move_pages (2),
90 .\" .BR migrate_pages (2),
91 .BR perf_event_open (2),
92 .\" .BR process_vm_readv (2),
93 .\" .BR ptrace (2),
94 .BR sched_setaffinity (2),
95 .BR sched_setparam (2),
96 .BR sched_setscheduler (2),
97 .BR tgkill (2),
98 .BR timer_create (2)