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 ๐ŸŒธ


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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms