Debian Codegraph @

upstream/debian-trixie/man2/gettid.2

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