What happens when you type ls -l in the shell

What happens when you type ls -l in the shell

Before we get started let's first understand some basics of Linux Operating System.

WHAT IS THE SHELL ?

The shell is a user interface that allows to user to communicate with the hardware through the kernel.


WHAT IS A KERNEL ?

A kernel is the core of the operating system.

it's main purpose is the resources management like memory management and cpu scheduling.

it permits also the communication between the user and the machine .

No alt text provided for this image

SO NOW WE GET SOME KNOWLEDGE LET'S DIVE INTO THE HEART OF THE MATTER.

HOW THE SHELL WORKS ??

  • THE GETLINE FUNCTION :

When you open the shell prompt the executable waits for user to type commands

using getline function.

ssize_t getline(char **buffer, size_t *size, FILE *stream);
  • CHECK THE ALIASES :

An Alias is a shortcut to reference a command .

  • CHECK THE PATH

The path is an environment variable that tells the shell which directory to search for an executable .

  • SYSCALL : execve()
int execve(const char *pathname, char *const argv[], char *const envp[]);

The execve is a system call in c language that permits to execute an executable file.

it takes the pathname of the executable, an array of string containing the options and the flags and also an array of strings containing the environment variables.

for instance when we type ls -l in the shell terminal the pathname of ls will be passed as first argument of execve , an array of strings null terminated containing the pathname of the command as the first element, the next array's element contains the options of the command for instance -l

The ls command is used to list the containing of the working directory.

-l option permits to display the long format (permission , etc)

No alt text provided for this image

the execve syscall will be executed in child process

a child process is a sub-process executed inside the process of the program.

  • HOW TO CREATE A CHILD PROCESS

Fork() is a system call to create a copy of the current process

it returns -1 in case of failure , 0 if the current process is child process and the id of the child process if the current process is the father


Wait() permits to stop the father process until one of its children finished.

No alt text provided for this image


要查看或添加评论,请登录

karim bahri的更多文章

  • Artificial intelligence for dummies

    Artificial intelligence for dummies

    The artificial intelligence is a branch of computer science concerning the creation of smart machines able to perform…

  • Mutable, Immutable... everything is object!

    Mutable, Immutable... everything is object!

    if you are beginner or expert in python , you might know that python is entirely object unlike other language like c++…

  • What happens when you type gcc main.c

    What happens when you type gcc main.c

    A brief introduction : GCC (GNU Compiler Collection) was created in 1987 by GNU Project as a free software in the…

  • What happens when you type ls *.c

    What happens when you type ls *.c

    If you are a windows user then you should not be uncomfortable with the interface below This interface is called "File…

社区洞察

其他会员也浏览了