What happens when you type ls -l in the shell.

Victor Plaza
3 min readNov 24, 2020

What happend when you type “ls -l” so for understand what happend we start for the basic.

  • What is kernel?
  • What is shell?
  • What is the flags?
  • What is the commands?
  • System calls

What is the kernel?

The kernel is the central and most fundamental part of a computer operating system. It is a program that controls all other programs on the computer, talking to the hardware and software, very involved in resource management.

What is a shell?

The shell is a command-line user interface that feeds keyboard input to the operating system of a given computer. The most common and widely used shell program is bash, which is used on Linux systems. Bash is a replacement for the older Bourne shell (sh), which itself is a replacement for the Thompson shell (sh), the original UNIX shell of the same name developed by Ken Thompson.

What are the flags?

In computing, a flag is a value that acts as a signal for a function or process. The value of the flag is used to determine the next step in a program. Flags are usually binary flags, which contain a Boolean value (true or false). However, not all flags are binary, which means that they can store a range of values.

What are the commands?

A command is defined as the message sent to the computer by the user, and which will cause a response to the message. Commands are commands since they tell the computer device what it should do or execute next, depending on the command sent to it. Each operating system incorporates a certain number of basic commands, which allow for the execution of the simplest tasks with direct commands.

System calls.

System calls usually use a special instruction from the CPU that causes the processor to transfer control to a privileged code (usually the kernel), previously specified. This allows the privileged code to specify where it should connect, as well as the state of the processor.

When a system call is invoked, the execution of the program it invokes is interrupted and its data is saved, normally on its PCB (Process Control Block), so that it can continue to be executed later. The processor then begins to execute the low-privilege code instructions to perform the required task. When it finishes, it returns to the original process and continues its execution.

Now we need to know if we are inside the shell and how do we know that we are inside the shell? Well, it’s simple, we have to visualize the symbol called prompt ($) and once we visualize the prompt we know that we are inside the shell.

And once inside the shell we can execute the commands to interact and navigate inside it, in this case, we proceed to enter the command ls -l. Here what happens is that the shell first gets the line with a system call which is getline that receives as a parameter a string which in this case is “ls -l” and once it receives the string it is tokenized to later verify through a child process if this command entered is valid or not.

¿How do we validate if this command is correct or not?

Is verified by another call to the system which is “execve” that what makes this call is, first look in the PATH if this command is built-in and then check again in the PATH if it’s a command if it previously matches that the string is a built-in or a command will be executed and the result will be shown on the screen, once the shell is executed it waits for the next command to be executed.

--

--