Currently I am studying on Operting System and came to understand how commands work in Linux terminal.
Before we go, let us check out how Linux receive input from hardware and convey it to OS.
Basically, Linux control everything in file so Standard Input(so called stdin) in terminal what we type by keyboard is written in /dev/stdin in real time. then when you press enterreturn, OS raise interruption to the running proccess and reset PC(Program Counter) to the start of executing file that you input as "command"
Here with an example when you put ls -al in terminal
- your
ls -alis written in/dev/stdinfile in real time- when you press enter, OS raise interruption to OS. To be in more detail, OS embed "interruption code" to PC(Program Counter) by force
- reset PC(Program Counter) to the first line of
excuting fileofls- CPU run
excuting fileoflswhich is already defined somewhere in root/
Then how OS find ls file in root/ and execute it?
Actually every commands in terminal is exist as files somewhere in file system
and the path where excution file at is predefined at/etx/paths
#/etx/paths
1 /usr/local/bin
2 /usr/bin
3 /bin
4 /usr/sbin
5 /sbin
Otherwise, you would type /usr/bin/ls instead of ls