What happens when you type ls -l in the shell

Mauricio Sierra Cifuentes
4 min readNov 25, 2020

--

What is a Shell?

In computing, a shell is a computer program which exposes an operating system’s services to a human user or other program. In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer’s role and particular operation. It is named a shell because it is the outermost layer around the operating system.

Command-line shells require the user to be familiar with commands and their calling syntax, and to understand concepts about the shell-specific scripting language (for example, bash).

Graphical shells place a low burden on beginning computer users, and are characterized as being easy to use. Since they also come with certain disadvantages, most GUI-enabled operating systems also provide CLI shells.

Unix Shell

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems.

Users typically interact with a Unix shell using a terminal emulator; however, direct operation via serial hardware connections or Secure Shell are common for server systems. All Unix shells provide filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration.

Configuration files

Shells read configuration files in various circumstances. These files usually contain commands for the shell and are executed when loaded; they are usually used to set important variables used to find executables, like $PATH, and others that control the behavior and appearance of the shell. The table in this section shows the configuration files for popular shells.

What is a Kernel?

The kernel is a computer program at the core of a computer’s operating system with complete control over everything in the system.[1] It is an integral part of any operating system. It is the “portion of the operating system code that is always resident in memory”. It facilitates interactions between hardware and software components.

It handles the rest of startup as well as input/output (I/O) requests from software, translating them into data-processing instructions for the central processing unit. It handles memory and peripherals like keyboards, monitors, printers, and speakers.

The kernel’s interface is a low-level abstraction layer. When a process requests a service to the kernel, it must invoke a system call, usually through a wrapper function that is exposed to userspace applications by system libraries which embed the assembly code for entering the kernel after loading the CPU registers with the syscall number and its parameters (e.g., UNIX-like operating systems accomplish this task using the C standard library).

What happens when you type ls -l in the shell

· ls is a shell command that lists files and directories within a directory. With the -l option, ls will list out files and directories in long list format.

But how does this happen?

• Shell displays a message with the $ symbol which is the indicator that it is waiting for a command from the user.

• Shell reads what it receives through the getline function, which takes the line entered in standard input and stores it in a buffer.

• The strtok function is called which uses tokens to divide the string by means of a delimiter.

• Shell analyzes if the first token is an alias and if it is, it replaces the alias with the real command.

• Shell uses the fork () system call to create child processes (children) which come to work in the foreground, the parent process waits for the children to terminate through wait ().

• Use the execve system call to execute.

• Fork () receives 2 values, one from the parent and the other from the child, depending on the value it is known if it was successful or not.

• Close the Shell with ctrl D or ctrl C

Here a flowchart of our shell operation

Authors:

Soren Acevedo Azuero

Mauricio Sierra Cifuentes

--

--

No responses yet