]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/gettid.2
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man2 / gettid.2
CommitLineData
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.\"
4c1c5274 6.TH gettid 2 (date) "Linux man-pages (unreleased)"
fea681da
MK
7.SH NAME
8gettid \- get thread identification
4ae0b242
AC
9.SH LIBRARY
10Standard 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
21returns the caller's thread ID (TID).
22In a single-threaded process, the thread ID
23is equal to the process ID (PID, as returned by
24.BR getpid (2)).
25In a multithreaded process, all threads
fea681da 26have the same PID, but each one has a unique TID.
fd484056 27For further details, see the discussion of
1ae6b2c7 28.B CLONE_THREAD
fd484056
MK
29in
30.BR clone (2).
47297adb 31.SH RETURN VALUE
56d898aa 32On success, returns the thread ID of the calling thread.
fea681da
MK
33.SH ERRORS
34This call is always successful.
12afd1b4
MK
35.SH VERSIONS
36The
37.BR gettid ()
38system call first appeared on Linux in kernel 2.4.11.
ed474f00
MK
39Library support was added in glibc 2.30.
40(Earlier glibc versions did not provide a wrapper for this system call,
ed474f00
MK
41necessitating the use of
42.BR syscall (2).)
3113c7f3 43.SH STANDARDS
60a90ecd 44.BR gettid ()
8382f16d 45is Linux-specific and should not be used in programs that
fea681da 46are intended to be portable.
c12fd10d 47.SH NOTES
fd484056
MK
48The thread ID returned by this call is not the same thing as a
49POSIX thread ID (i.e., the opaque value returned by
50.BR pthread_self (3)).
efeece04 51.PP
4a8f7185
MK
52In a new thread group created by a
53.BR clone (2)
54call that does not specify the
1ae6b2c7 55.B CLONE_THREAD
4a8f7185
MK
56flag (or, equivalently, a new process created by
57.BR fork (2)),
58the new process is a thread group leader,
59and its thread group ID (the value returned by
b3eb2280 60.BR getpid (2))
4a8f7185
MK
61is 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)