← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Google software engineering interview, system design flavored technical phone screen that went pretty deep into Linux internals. One question, but it had a lot of moving parts and I felt like I was constantly playing catch-up.

Questions Asked (1)

Q1

Walk me through everything that happens under the hood when a user types `ls` in a shell and hits Enter. Cover the shell's behavior, how the binary gets located and executed, the relevant system calls and kernel filesystem interactions, how directory entries and file metadata get retrieved, and how flags like `-l`, `-a`, and `-R` change any of that.

System DesignTechnical Trade-offs
Author's notes

This question is deceptively wide.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Structure your answer as a chronological narrative from user input to output, covering shell parsing, process creation, binary loading, system calls, and filesystem operations. Emphasize the kernel's role and how flags alter the syscall patterns and data retrieval. Use clear transitions between phases to show depth and coherence.

Pro tip: Mention that `ls` uses `getdents`/`getdents64` to read directory entries and `stat`/`lstat` for metadata, and that `-l` triggers per-file stat calls while `-R` causes recursive directory traversal—this demonstrates practical kernel knowledge.

1. Shell reads and parses input

The shell reads the command line, tokenizes it into 'ls', and checks for aliases, built-ins, or functions. Since 'ls' is not a built-in, it proceeds to locate the executable.

2. Locate and execute the binary

The shell searches the PATH environment variable for an executable named 'ls', then uses fork() to create a child process and execve() to replace the child's image with /bin/ls. The kernel loads the ELF binary, sets up memory, and transfers control.

3. ls opens and reads the directory

ls calls opendir() (which uses open() with O_DIRECTORY) to get a file descriptor for the current directory, then repeatedly calls readdir() (backed by getdents64 syscall) to retrieve directory entries.

4. Retrieve metadata and format output

For each entry, ls may call stat() or lstat() to get file metadata (size, permissions, timestamps). It then formats the output according to flags and writes to stdout using write().

5. Explain flag effects

Describe how -a includes hidden files (entries starting with '.'), -l triggers detailed stat calls and long format, and -R recursively traverses subdirectories, repeating the open/read/stat cycle for each.

Key Points to Mention

  • Shell parsing, PATH resolution, and fork/execve sequence.
  • Kernel's role in loading the ELF binary and setting up the process.
  • System calls: open, getdents64, stat/lstat, write, and their purposes.
  • Directory entries vs. file metadata: getdents returns names and inodes; stat retrieves inode details.
  • Flag impacts: -a shows hidden files, -l uses stat for long listing, -R recurses into subdirectories.
  • Buffering and output: ls may buffer output and use write syscalls to display results.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.