Why a Program's First Argument Is the Name Itself?

2 naman5a 1 8/12/2025, 5:06:05 PM cpu.land ↗

Comments (1)

naman5a · 2h ago
You know that convention where a program’s first argument is the name of the program? Behind the scenes the Program For Execution needs to go to Kernel where it will be executed by syscall .

The syscall for execution is execve and the call signature for that is int execve(const char filename, char const argv[], char *const envp[]);

The filename argument is passed to a getname() function, which copies the string from user space to kernel space and does some usage tracking things. It returns a filename struct, which is defined in include/linux/fs.h. It stores a pointer to the original string in user space as well as a new pointer to the value copied to kernel space: