Skip to content
Laviyx Learn

Try

Linux and Bash course menu

Advanced Linux Interview Questions and Answers

Advanced Linux interview questions with answers for DevOps and SRE roles: the boot process, troubleshooting a slow server, memory, file descriptors, namespaces and cgroups, and what happens when you run a command.

Advanced5 min readUpdated
On this page

DevOps, SRE and senior developer interviews focus on how Linux works, and how you diagnose problems.

How it works#

1. Describe the Linux boot process.#

Show solution

The firmware (UEFI or BIOS) starts a boot loader such as GRUB, which loads the kernel and an initial RAM disk. The kernel sets up hardware, mounts the root file system, and starts PID 1, usually systemd. systemd then starts services until it reaches the target, such as multi-user.target.

2. What happens when you run ls in a shell?#

Show solution

The shell parses the line, expands variables and wildcards, and looks for the command among aliases, functions and builtins, then in PATH. It calls fork to create a child, and the child calls exec to load /usr/bin/ls. The parent waits, and stores the exit status in $?.

3. What is a file descriptor?#

Show solution

A number that a process uses to refer to an open file, socket or pipe. 0, 1 and 2 are stdin, stdout and stderr. Limits are shown by ulimit -n, and "too many open files" means that a process hit the limit. /proc/PID/fd lists them.

4. What is the difference between a process and a thread?#

Show solution

A process has its own memory space. Threads share the memory of their process, so they are cheaper to create and communicate faster, but they need synchronisation.

5. What are namespaces and cgroups?#

Show solution

Namespaces isolate what a process can see (PIDs, network, mounts). cgroups limit what it can use (CPU, memory). Together they are the kernel features behind containers such as Docker.

6. What is /proc?#

Show solution

A virtual file system that presents kernel and process information as files. /proc/cpuinfo, /proc/meminfo and /proc/PID/ are common examples. /sys is similar, for devices and kernel settings.

7. Explain how memory appears in free.#

Show solution

Linux uses spare memory for disk cache, so "free" is often low, and that is normal. The available column is the true estimate of memory for new programs. Heavy swap use is the real warning sign.

8. What is the OOM killer?#

Show solution

When the system runs out of memory, the kernel picks a process and kills it, to keep the system alive. Check with dmesg or journalctl -k. A sudden process death with no error log is a common sign.

9. What are setuid and the sticky bit?#

Show solution

setuid makes a program run with its owner's rights, which is how passwd updates a root-owned file. The sticky bit on a folder such as /tmp means that only a file's owner can delete it.

Troubleshooting#

10. A server is slow. How do you investigate?#

Show solution

Check uptime for load, then top for CPU and memory, separating user time from iowait. Use free -h for memory and swap, df -h for disk, iostat and iotop for disk activity, and ss and sar for network. Then read the logs of the busy process.

11. A website is not loading. What are your steps?#

Show solution

Check DNS with dig, reachability with ping, and the port with nc -zv host 443. Use curl -v for the HTTP answer. On the server, check systemctl status, ss -ltn, the firewall, disk space, and the application logs.

12. CPU is low, but load is high. What does this mean?#

Show solution

Tasks are waiting, usually on disk or network I/O. Look for processes in state D, and check iowait in top.

13. You cannot delete a file, even as root. Why?#

Show solution

It may have the immutable attribute (check with lsattr, and clear with chattr -i), the file system may be mounted read-only, or a disk error may have forced it to read-only.

14. A process cannot be killed, even with kill -9. Why?#

Show solution

It is in uninterruptible sleep (D), usually waiting for I/O, such as a hung network disk. Or it is a zombie, which is already dead, and needs its parent to read its status.

15. How do you see what system calls a program makes?#

Show solution

strace -p PID, or strace command. It helps when a program hangs or fails silently, for instance on a file it cannot open. Use it with care in production, because it slows the process.

Security and scripting#

16. How do you secure a new server?#

Show solution

Update packages, create a normal user with sudo, use SSH keys, disable password and root login, enable a firewall with only the needed ports, install fail2ban, turn on automatic security updates, and run services as unprivileged users.

17. What is the difference between a subshell and the current shell?#

Show solution

Commands in ( ), pipelines and $( ) run in a child process, so variables set there are lost. { ...; } and source run in the current shell.

18. Why is parsing ls output a bad idea?#

Show solution

File names can contain spaces, newlines and other special characters. Use globs (for f in *), or find -print0 | xargs -0.

19. What are the limits of set -e?#

Show solution

It does not trigger for commands in if or while tests, or before && and ||, and failures in $( ) can be hidden, especially inside local x=$(cmd). Explicit checks are still needed for important steps.

20. How do you make a script safe to run twice?#

Show solution

Make it idempotent: use mkdir -p, check for existing state, write to a temporary file and mv it into place, and take a lock with flock.

Finished this lesson?