program_invocation_name(3)
β¨ program_invocation_name β okay bestie, let's learn ur own name β¨
so like... you ever wanted to know what ur program is literally CALLED? Not what you named the file, not what someone typed β the actual thing that got typed to launch it? Yeah. That's this. It's a libc moment. It's Linux man-pages 6.20, dated 2026-02-08, and it's from the Library Functions Manual because we're fancy like that. π
π NAME π
program_invocation_name, program_invocation_short_name β snag the name that was used to invoke the calling program π«Ά
π LIBRARY π
Standard C library β rock that libc, link it with -lc. Periodt. β¨
πΈ SYNOPSIS πΈ
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <errno.h>
extern char *program_invocation_name;
extern char *program_invocation_short_name;
π head's up bestie β you NEED that#define _GNU_SOURCEup at the very top before the includes, or the compiler is gonna be like "who?? never heard of her." It's giving gatekept. The docs even point you atfeature_test_macros(7)if you wanna read up. π
π DESCRIPTION π
So program_invocation_name holds the name that was used to invoke the calling program. π
And the tea? It's the same thing as the value of argv[0] in main() β BUT, and this is the part that matters, program_invocation_name is global scope. So like, anywhere in ur code can peek at it, not just main(). Main character energy fr fr. π
Then there's program_invocation_short_name, which contains the basename component of the name used to invoke the calling program. Translation: it's the same value as program_invocation_name, except everything up to and including the final slash (/) gets chopped off β if there even was a final slash. πͺ
And here's the cute part: these variables get automatically initialized by the glibc run-time startup code. You don't gotta do a single thing. She just shows up ready. β¨
π¦ VERSIONS π¦
Heads up: the Linux-specific /proc/pid/cmdline file gives you access to similar info if you wanna go that route. Different vibe, same-ish intel. π
π STANDARDS π
GNU. That's it, that's the standard. π
π SEE ALSO π
and that's the whole lore, bestie π This lil page came from Linux man-pages 6.20, last touched 2026-02-08, and it lives in section 3 (the library functions girlies). Go forth and print ur own name, icon. ππ«Ά
π¦ 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
- Copyright 2006, 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