[Linux Internals]: What happens when you type ‘ls -l’ command in the terminal?
- Terminal is nothing but a wrapper that runs shell (bash or ksh etc) and allows us to enter commands
- Shell breaks down the commands entered by parsing
- It checks for shell expansion ( ex: ls * ) [ Resource: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html ]
- It checks for aliases for that command
- Tries to find the location of the command by searching under $PATH
- If it finds, it executes it!
- During the execution, libraries required by the program are loaded into the memory at the run time; If you run “ltrace or strace” on the command you can see library calls like mmap() [strace for system calls / ltrace for library calls]. Loading of libraries can happen through dynamic loading or static loading. Shell will use system calls to load these libraries while running the command.
Execution of program :