5. Operating systemsRunning a program
Running a program
Running a program is the chain of steps an operating system takes to turn a file on disk into a live process. On Unix-like systems the shell calls fork, which creates a near-copy of itself; this is cheap thanks to copy-on-write, where parent and child share memory pages until one of them writes. The child then calls exec, which discards its memory image and replaces it with the new program. The kernel maps the executable’s code and data into memory, and for most programs a dynamic linker then maps shared libraries, like the C standard library, and wires up the functions the program calls in them. Only then does execution reach the program’s startup code and main.
In this lesson: Step through fork, exec, loader and linker.