What Happens When You Type cat /etc/passwd
?
Before some interviews I had a look to see what kinds of things were
typically asked. One of the common ones for Linux was "What exactly
happens when you type cat /etc/passwd
?" (Or basically execute a
command.) I was somewhat surprised to actually get
this
unoriginal
rote
question.
What really bugged me was that I was dismissed from consideration as "not knowing enough about Linux" because of this question (the only one that was asked about Linux). My answer was "Well, I don’t really know. But it involves some stuff like fork() and exec() and [a ton of other details I could remember]." I now feel like the correct part about that really was the "I don’t know" since I’m pretty confident that nobody really does.
Wanting to explore why I felt that "I have almost no clue" is actually a better answer than the ones that are typically advised, I looked into the topic in more detail. What follows is my limited and perhaps heavily flawed account of what happens when commands are run. The one thing I am certain of is that I’m glossing over 99.999% of it. There are also probably outright counterfactual errors. But I think this is sufficient to establish that, yes indeed, it is complicated, and that I have given it some thought.