← Questions
What happens when you run ls
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Google's first round (coding), last asked Feb 2026. It tests operating systems and linux.
On Linux, a user types ls in a shell and presses Enter. Explain the whole path from the keystroke to the listing on the screen.
What to cover
- The shell: reading the line, parsing it, expanding aliases and globs, checking for built-ins.
- Finding the program: searching each directory of
PATH, the shell's hash table of known commands. - Starting it:
fork(orclone), thenexecvein the child; the kernel loading the ELF file, the dynamic linker mapping shared libraries; the parent waiting withwaitpid. - Reading the directory:
openaton the directory,getdents64to read entries, the virtual filesystem layer and the dentry and inode caches, the concrete filesystem below. - Metadata: what changes with
-l(astatorstatxcall per entry, user and group names looked up through/etc/passwdand/etc/groupor NSS), with-a(entries starting with a dot are shown), and with-R(recursing into subdirectories). - Output: writing to standard output, the terminal or pseudo-terminal driver, the terminal emulator drawing it; colours and column layout only when output is a terminal (
isatty). - Exit: the exit status,
SIGCHLD, the shell printing the next prompt.
Clarifying questions
- Which shell, and is
lsaliased (for example tols --color=auto)? - A local filesystem, or a network filesystem such as NFS?
- How deep should I go: system calls, or down to page cache and disk?
What a strong answer covers
- A correct ordering of shell, kernel and filesystem steps, with system call names where they matter.
- The difference between reading directory entries (names and inode numbers) and reading metadata (one
statper entry), and whyls -lon a huge directory is slow. - Caches that make the second run faster.
- How to check all of this:
strace ls -l,ltrace,type ls.
Follow-ups
- Why can
lshang on a network mount, and what does that look like instrace? - What is different when you run
ls | wc -l? - A directory has 10 million files. What breaks, and what do you use instead?
Where it's asked
- Google · First round: coding · Last asked Feb 202645 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
What it tests
operating systems · linux
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
