Outils pour utilisateurs

Outils du site


issue190:c_c

I was observing – not participating in – a discussion on shells and realizing there is a large gap in what a shell is, where it fits in, and what the perception is thereof. This issue, I want to explain the difference between the kernel and a shell. Imagine a three-layer cake. The bottom layer is your kernel, the middle layer is your shell, and the top layer is your application layer. The kernel is all about handling hardware. When I say handling hardware, what I mean is that it allocates memory or it handles input & output, say to your disk. In other words, it manages stuff. Something needs CPU time, the kernel will schedule that. All the security and protection also happens here, within the kernel. So, when a system call happens, it is what responds to that system call. This may not be of interest to you, but to understand what a system call is, think of it this way – when you ‘call’ the system to send a packet over the network, or ‘call’ the system to read a file from disk, or call the system to do some task for us, that is a system call. I don’t know how this makes sense to a native English speaker, but to me it made no sense at first, but instead of thinking of your mother calling you to come inside, think of it more of a telephone call where you order some sand to be delivered at your home, so you can mix cement to build a wall.

J’observais – je n’y participais pas – une discussion sur les shells et je me rendais compte du fait qu’il y a un grand écart entre ce qu’est un shell, où il se place et la perception qu’en ont les gens. Dans ce numéro-ci, je veux expliquer la différence entre le noyau et un shell. Imaginez un gâteau qui a trois niveau. Le niveau du bas est le noyau, le niveau du milieu est le shell et le niveau du haut est celui des applications. Le noyau gère le matériel. Quand je dis cela, je veux dire qu’il répartit la mémoire ou qu’il gère les entrées et les sorties, disons de et vers votre disque. Autrement dit, il gère des trucs. Un truc a besoin d'un peu de temps du processeur et le noyau planifiera ce qui est nécessaire. Toute la sécurité et la protection a lieu à l’intérieur du noyau aussi. Ainsi, quand un appel système a lieu, c’est le noyau qui y répond. Cela peut ne pas vous intéresser, mais pour comprendre ce qu’est un appel système, pensez-y ainsi : quand vous « appelez » le système pour envoyer un paquet sur le réseau, ou « appelez » le système pour qu’il lise un fichier sur le disque ou appelez le système pour qu’il accomplisse une tâche pour nous, c’est cela un appel système. Je ne sais pas comment cela semble logique à un anglophone, mais, pour moi, au départ c’était du non-sens ; mais au lieu de penser à votre mère qui vous appelle pour rentrer à la maison, pensez-y davantage comme un coup de fil pendant lequel vous commandez du sable qui sera livré chez vous afin que vous puissiez faire du ciment pour construire un mur.

The shell is an interface between the user and the system and the kernel is an interface between system calls and the actual hardware. You may also hear people talking about ‘spaces’ – kernel space and user space. This simply groups things together into the ‘space’ where they ‘live’. VLC player and Inkscape are applications that live in user space. You, as the user, interact with them. You do not get to do things in the kernel space. For instance, the memory manager lives in the kernel space and it allocates memory for VLC or Inkscape, but you do not get to interact with it. Think of it as a lunch counter. You can order food here, the person behind the counter (the system call interface) takes your order and passes it on to the kitchen (the kernel), and out pops your food. You do not get to interact with the stove or the ingredients, but when you order a hot dog and chips, you get a hot dog and chips. We can see how long a command spends in each by using the ‘time’ command on the command-line. Type: time ls

Le shell est une interface entre l’utilisateur et le système ; le noyau est une interface entre les appels système et le matériel.

Vous pouvez aussi entendre parler d’« espaces » - espace noyau et espace utilisateur. Cela ne fait que regrouper les trucs ensemble dans l’« espace » où ils « vivent ». Le lecteur VLC et Inkscape sont des applications qui vivent dans l’espace utilisateur. Vous, en tant qu’utilisateur, interagissez avec elles. Vous n’avez pas le droit de faire des choses dans l’espace noyau. Par exemple, le gestionnaire de mémoire vit dans l’espace noyau et alloue la mémoire pour VLC ou Inkscape, mais vous ne pouvez pas interagir avec ce gestionnaire. Pensez-y comme à un comptoir pour un casse-croûte. Vous pouvez y commander de la nourriture et la personne derrière le comptoir (l’interface des appels système) accepte votre ordre et le donne à la cuisine (le noyau), et voilà votre repas. Vous ne pouvez pas interagir avec la cuisinière ou les ingrédients, mais quand vous commandez un hotdog et des chips, vous recevez un hotdog et des chips.

Nous pouvons voir combien de temps une commande passe dans chacun des espaces en utilisant la commande « time » dans le terminal. Tapez : time ls

Look at the output, does it make sense to you? You will see: • “real” meaning real time, • “user” meaning time spent in user space and, • “sys” meaning time spent in kernel space Yes, I know, but go with the flow here, it is meant for n00bs. (I found out why I had to rewrite week 47 & 48 last year…doh). Let us do something a little more intensive to get values all around. If you have a directory with stuff in it, (no use on an empty one!), type: time md5sum * This simply prints out the MD5 hash of the file, before printing out the file name. If you don’t know what a MD5 hash is, ask.

Regardez la sortie. Est-ce qu’elle vous semble logique ?

Vous verrez : •• « real », ce qui signifie en temps réel, •• « user », ce qui signifie le temps passé dans l’espace utilisateur et •• « sys », ce qui signifie le temps passé dans l’espace du noyau

Oui, je sais, mais restez avec moi, ma cible, ce sont les vrais débutants.

(J’ai découvert pourquoi j’ai dû refaire les semaines 47 et 48 l’année dernière… c’était évident.)

Faisons quelque chose d'un peu plus intensif pour avoir des valeurs partout. Si vous avez un répertoire avec des trucs dedans (inutile sur un répertoire vide !), tapez : time md5sum *

Cela ne fait qu’imprimer le hash MD5 du fichier, avant d’imprimer le nom du fichier. Si vous ne savez pas ce qu’est un hash MD5, demandez.

This can be a crude indication of where your command or program spends its time. Go ahead, try it with, say, Python (shown below) or whatever program you wish. We used our terminal emulator (an application living in user space) to use the shell, in my case bash, to do something (make a system call). The kernel allocated memory, handled the i/o for writing that file to disk, etc, and the ordered python program popped out, just like our hot dog example. You did not get to interact with the i/o interface, the memory manager, or the process manager, but you got your Python program. The Python program was my wall, the command I used in my shell (bash) made a system call to write a file to disk (a telephone call to order sand) – is this coming together for you yet? No? Play a *quick game of Sins of a solar empire, and come back. That’s as short ‘n sweet as I can make it (with my brain running in a million directions, whilst I try to herd those 100 cats). If you still have trouble understanding what a shell is, and where it fits in with regards to the kernel, read that again. Just kidding, drop us a line on: misc@fullcirclemagazine.org

Cela peut donner une indication approximative de l’endroit où votre commande ou programme passe son temps. Allez-y, essayez avec, disons, Python (voir ci-dessous) ou le programme que vous voulez.

Nous avons utilisé notre émulateur de terminal (une application qui vit dans l’espace utilisateur) pour utiliser le shell, dans mon cas bash, pour faire quelque chose (un appel système).

Le noyau a alloué de la mémoire, géré les entrées/sorties (E/S) pour écrire ce fichier sur le disque, etc. et voilà le programme python demandé, tout comme notre exemple du hotdog. Vous ne pouviez pas interagir avec l’interface des e/s, le gestionnaire de mémoire ou le gestionnaire du processus, mais vous avez obtenu votre programme Python. Le programme Python était mon mur, la commande que j’ai utilisée dans mon shell (bash) a fait un appel système de l’écriture d’un fichier sur le disque (un appel téléphonique pour commander du sable) – est-ce que cela commence à avoir du sens pour vous ? Non ? Alors, jouez rapidement à Sins of a solar empire et revenez me voir.

C’est aussi précis et concis que possible pour moi (avec le cerveau qui court dans des milliers de directions pendant que j’essaie de rassembler les cent chats). Si vous ne voyez toujours pas ce qu’est un shell et sa place par rapport au noyau, relisez l’article. Je plaisante, écrivez-nous sur : misc@fullcirclemagazine.org

issue190/c_c.txt · Dernière modification : 2023/02/28 11:53 de andre_domenech