gettid(2)
โจ gettid(2) โ the "who am I tho" syscall โจ
okay bestie, welcome to gettid(2) from the System Calls Manual ๐ this is the little guy that tells a thread its own name. slay.
๐ NAME ๐
gettid โ get thread identification
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ฆ SYNOPSIS ๐ฆ
#define _GNU_SOURCE
#include <unistd.h>
pid_t gettid(void);
๐ DESCRIPTION ๐
So gettid() returns the caller's thread ID (TID). that's it. that's the whole vibe. it's giving "mirror mirror on the wall" but the wall is the kernel and the mirror is a syscall ๐ช
In a single-threaded process, the thread ID is the same as the process ID (PID, as returned by getpid(2)). one thread, one id, no drama, no cap.
In a multithreaded process, all threads have the same PID, but every single one has a unique TID. like, they all share a last name but got their own government name, you know? ๐
For further details, go read the discussion of CLONE_THREAD in clone(2). that's where the lore lives, bestie.
๐ RETURN VALUE ๐
On success, it returns the thread ID of the calling thread. literally just a pid_t with your name on it ๐ซถ
๐ ERRORS ๐
This call is always successful. it cannot fail. it has never known failure. main character energy fr fr. โจ
๐ STANDARDS ๐
Linux. that's it, that's the list. ๐ง
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
Linux 2.4.11, glibc 2.30. vintage but make it iconic.
๐ NOTES ๐
The thread ID returned by this call is not the same thing as a POSIX thread ID (i.e., the opaque value returned by pthread_self(3)). bestie do NOT mix these up, they are two different girls with the same nickname ๐ญ
In a new thread group created by a clone(2) call that does not specify the CLONE_THREAD flag (or, equivalently, a new process created by fork(2)), the new process is a thread group leader, and its thread group ID (the value returned by getpid(2)) is the same as its thread ID (the value returned by gettid()). so in that case they match. twin behavior. ๐ง
๐ธ SEE ALSO ๐ธ
capget(2)clone(2)fcntl(2)fork(2)get_robust_list(2)getpid(2)ioprio_set(2)perf_event_open(2)sched_setaffinity(2)sched_setparam(2)sched_setscheduler(2)tgkill(2)timer_create(2)
okay that's the whole page bestie, go find out who you really are ๐ช๐ this was Linux man-pages 6.20, dated 2026-02-08, and yes she ate. periodt. ๐ โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2003, Abhijit Menon-Sen <ams@wiw.org>
- Copyright 2008, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms