Settings

Theme

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

cpu.land

3 points by naman5a 4 months ago · 1 comment

Reader

naman5aOP 4 months 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:

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection