What Actually Happens When You Run a Program?
When we type:
./hello
it feels like something very simple happens.
We execute a file, and suddenly a program is running.
But from the operating system's point of view, there is a lot more going on.
This post is a small journey from a command in the shell to a running process.
1. The Shell
First, the shell receives our command:
./hello
The shell doesn't magically execute the file itself.
A typical Unix shell creates a new process and asks the operating system to replace that process's program image with the requested executable.
One important system call involved here is:
execve();
For example:
char *argv[] = {
"./hello",
NULL
};
execve("./hello", argv, NULL);
The interesting thing about execve() is that