KatInterview

Inside a Linux Command: Processes, Files, Containers vs VMs

System DesignModel answer
MediumModel answerSystem Designlinuxoperating-systemsprocesses

Last updated

Trace a Linux command from shell parsing to exit status, explain path lookup, permissions, file descriptors and /proc, then compare containers and VMs by isolation boundary.

You are asked to explain, at the operating-system level, what Linux does when people use everyday commands and when they choose an isolation technology. Name the user-space work, the system calls, the kernel objects involved, the permission checks, and the ways each step can fail. Do not treat any command as a black box.

State your assumptions first (for example, a Bash-like shell on Linux, and whether namespaces and cgroups are in scope).

Part 1: From typed line to running program

  • A user types an external command. Describe everything between the Enter key and the shell showing the next prompt: parsing, expansion, executable lookup, process creation, program loading, waiting, and exit status.
  • Contrast this with a builtin such as cd. Why can't a separate program change the shell's working directory?
  • At a high level, how do ls, pwd, ip, and an older tool such as ifconfig get their answers?

Part 2: Files, directories, permissions, and /proc

  • How does a process turn a path string into an open file? Cover directory entries, inodes, and file descriptors.
  • How is a directory different from a regular file? How do read, write, and execute bits apply to each, and which credentials are checked?
  • What do the main top-level directories hold?
  • Why is /proc not an ordinary directory on disk?

Part 3: Containers versus virtual machines

  • Compare the two on isolation boundary, kernel sharing, startup time, resource overhead, security, and operations.
  • Give example workloads where each is the better choice, and say what you would do when neither extreme fits.

Hints

Hint 1

For Part 1, think about which process attributes are inherited across fork and which are replaced by exec. Working directory belongs to a specific process.

Hint 2

For Part 2, separate three layers: the directory entry (name to inode), the inode (owner, mode, data), and the per-process file descriptor that points to an open file description with its own offset.

Hint 3

For Part 3, ask which component an attacker must compromise to escape: a shared kernel with a large syscall surface, or a hypervisor with a narrow interface. Then connect that to startup time and density.