Debian Codegraph @

upstream/debian-unstable/man2/gettid.2

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