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

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.

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

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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store