]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org> |
fd484056 MK |
2 | .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com> |
3 | .\" | |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da | 5 | .\" |
1d767b55 | 6 | .TH GETTID 2 2021-03-22 "Linux" "Linux Programmer's Manual" |
fea681da MK |
7 | .SH NAME |
8 | gettid \- get thread identification | |
4ae0b242 AC |
9 | .SH LIBRARY |
10 | Standard C library | |
8fc3b2cf | 11 | .RI ( libc ", " \-lc ) |
fea681da | 12 | .SH SYNOPSIS |
16718a1c | 13 | .nf |
7996b4e4 MK |
14 | .B #define _GNU_SOURCE |
15 | .B #include <unistd.h> | |
68e4db0a | 16 | .PP |
fea681da | 17 | .B pid_t gettid(void); |
c12fd10d | 18 | .fi |
fea681da | 19 | .SH DESCRIPTION |
60a90ecd | 20 | .BR gettid () |
fd484056 MK |
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 | |
fea681da | 26 | have the same PID, but each one has a unique TID. |
fd484056 | 27 | For further details, see the discussion of |
1ae6b2c7 | 28 | .B CLONE_THREAD |
fd484056 MK |
29 | in |
30 | .BR clone (2). | |
47297adb | 31 | .SH RETURN VALUE |
56d898aa | 32 | On success, returns the thread ID of the calling thread. |
fea681da MK |
33 | .SH ERRORS |
34 | This call is always successful. | |
12afd1b4 MK |
35 | .SH VERSIONS |
36 | The | |
37 | .BR gettid () | |
38 | system call first appeared on Linux in kernel 2.4.11. | |
ed474f00 MK |
39 | Library support was added in glibc 2.30. |
40 | (Earlier glibc versions did not provide a wrapper for this system call, | |
ed474f00 MK |
41 | necessitating the use of |
42 | .BR syscall (2).) | |
47297adb | 43 | .SH CONFORMING TO |
60a90ecd | 44 | .BR gettid () |
8382f16d | 45 | is Linux-specific and should not be used in programs that |
fea681da | 46 | are intended to be portable. |
c12fd10d | 47 | .SH NOTES |
fd484056 MK |
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)). | |
efeece04 | 51 | .PP |
4a8f7185 MK |
52 | In a new thread group created by a |
53 | .BR clone (2) | |
54 | call that does not specify the | |
1ae6b2c7 | 55 | .B CLONE_THREAD |
4a8f7185 MK |
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 | |
b3eb2280 | 60 | .BR getpid (2)) |
4a8f7185 MK |
61 | is the same as its thread ID (the value returned by |
62 | .BR gettid ()). | |
47297adb | 63 | .SH SEE ALSO |
76006a4a | 64 | .BR capget (2), |
fea681da | 65 | .BR clone (2), |
76006a4a | 66 | .BR fcntl (2), |
fea681da | 67 | .BR fork (2), |
76006a4a | 68 | .BR get_robust_list (2), |
c8fb1c6d | 69 | .BR getpid (2), |
76006a4a MK |
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), | |
0ec954ee MK |
80 | .BR tgkill (2), |
81 | .BR timer_create (2) |