]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/gettid.2
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man2 / gettid.2
1 .\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
2 .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH GETTID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
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 .PP
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 VERSIONS
36 The
37 .BR gettid ()
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
42 .BR syscall (2).)
43 .SH CONFORMING TO
44 .BR gettid ()
45 is Linux-specific and should not be used in programs that
46 are intended to be portable.
47 .SH NOTES
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)).
51 .PP
52 In a new thread group created by a
53 .BR clone (2)
54 call that does not specify the
55 .B CLONE_THREAD
56 flag (or, equivalently, a new process created by
57 .BR fork (2)),
58 the new process is a thread group leader,
59 and its thread group ID (the value returned by
60 .BR getpid (2))
61 is the same as its thread ID (the value returned by
62 .BR gettid ()).
63 .SH SEE ALSO
64 .BR capget (2),
65 .BR clone (2),
66 .BR fcntl (2),
67 .BR fork (2),
68 .BR get_robust_list (2),
69 .BR getpid (2),
70 .\" .BR kcmp (2),
71 .BR ioprio_set (2),
72 .\" .BR move_pages (2),
73 .\" .BR migrate_pages (2),
74 .BR perf_event_open (2),
75 .\" .BR process_vm_readv (2),
76 .\" .BR ptrace (2),
77 .BR sched_setaffinity (2),
78 .BR sched_setparam (2),
79 .BR sched_setscheduler (2),
80 .BR tgkill (2),
81 .BR timer_create (2)