What happens when I Type ls -l *.c under the hood.
The objective of this article is to talk a bit about ehat happens under the hood when we execute commands in the shell, but mainly we will talk about what happens when we execute 'ls'. The role of the shell is to?interpret?the input provided by the user, and provide output in response to be displayed by the terminal. The most obvious output produced by the shell is the?prompt, which typically looks like this:
This is just a sign indicating that a new has started, this sign could be any other sign, but this is the most common, in the other cases the '#' sign is used, or as I said before any other sign or text. After that you can put the command designed for the program to do whatever you want to do, for example ls -l *.c Which makes a detailed list of all the .c files in the current directory, something like this:
What really happens when we execute this command are a series of checks to see if it is a "built in" command or it is not, in the event that it was not a command (! Built in), it would look for the program in the path, where it is checking in which of all the existing directories, is the program that executes the 'ls' line.
But when I talk about path, I don't mean this:
What I really mean is a set of directories where the program files are located, and actually it looks like this:
领英推荐
The way to get the path is with the command echo $PATH, continuing with the them, the command is added to each of these directories separated by a colon as indicated on the image. Although I think I skipped something, Let's talk a bit about what shell is; The shell is an aplicattion which connects user inputs to kernel, in other words is an interpreter commands.
To dig a little deeper into what happens when we type "ls -l *.c", we will make a list of the steps to make it more detailed and graphic:
STEP 1, Using getline function, the program read and store the input line.
STEP 2, Separate lines using strtok function and stotre into the array by positions.
To be continue...