Skip to main content

How does Program Execute in Linux

The shell forks itself then exec to replace the child with the program that we would like to run. The parent which is the shell, calls wait on the child in order to wait for it's return value. The stdin, stdout are also connected in order for the outputs from the child to be displayed properly. Otherwise, you wouldn't be able to see the output of find command. For example.

https://unix.stackexchange.com/questions/225736/how-does-a-shell-execute-a-program

https://stackoverflow.com/questions/4204915/please-explain-the-exec-function-and-its-family

https://fsl.fmrib.ox.ac.uk/fslcourse/unix_intro/shell.html -> very nice simple explanation of how unix interpreter works. Interpreter can be used interchangeably with shell. They are referring to the same thing, a program that reads in prompt, execute the program, wait for child, and repeat.

https://www.reddit.com/r/bash/comments/ugoz97/today_i_understood_the_importance_of_the_shebang/ -> Explains what is shebang