This Is What Happens When You Type A Command Into A Terminal

Cheryl Abram
2 min readMay 5, 2022
teletype machine

This is an image of a teletype. The teletype was an example of an early day hardcopy terminal and predated the use of a computer screen by decades.

Here’s what happens when you type a command into the terminal.

Below this picture is a semi-detailed explanation of what occurs.

my diagram of the TCP/IP layers

1.The function getline () reads your input and stores it into a buffer as a string

2.The function “strtok()” separates the tokens (individual words) which the shell sees as anything divided by a space delimiter tokens from the input

3.Command is checked for an alias

4.Tokens are stored and shell runs the built-in

5.Shell searches for the executable file for “ls” (/usr/bin/ls)

6.Shell creates a child process with the system call “fork()”

7.Fork creates a news child process almost identical to the “parent” calling it; the system call suspends execution of the calling process until the child process terminates

8.“ls” command is executed with the system call “execve()” in the child process. All the options and arguments are passed to the command, so you get the results you asked for from the shell

9.The results of your command are written to STDOUT, which is by default the terminal screen

10.Command prompt appears…waiting for the next command

Read more details about this process at https://www.tabbykatz.com/writings/ls-l-in-the-shell

Notice all the analog actions that occur (at incomprehensible speeds!). What are they? Here are a few:

1. a function reads and stores

2. another function separates

3. the command is checked

What are the others? Think about what happens in the physical world when you perform these actions. What do you do when you “read”? What do you do when you separate?

If your goal, is to produce an output for someone, what are the risks (threats and opportunities) you face when you perform these actions?

I’ll be back to break this down further.

--

--

Cheryl Abram
Cheryl Abram

Written by Cheryl Abram

A spiritual doula working in cybersecurity. Follow me on YouTube http://www.youtube.com/personcenteredcyber & LinkedIn.

No responses yet