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