Chapter 17: Interview Questions and Job Readiness
17.3 Linux ops refresh
Why: the problem
The most common hands-on DevOps question in India is simple: "The website is down. You have SSH access to the Linux server. What do you type?" It is asked at Infosys, Wipro, Accenture and in startup rounds. Some panels even give you a real broken VM and watch your screen. If you freeze, you fail. If you type a calm sequence of checks, you pass, even if you do not find the bug in time. This lesson gives you that sequence. You will break an nginx server in three different ways on your own Ubuntu machine: stop the service, fill the disk and take the port with another program. Each time you will find it with the same first checks. By the end, the triage order will be in your fingers.
What we will build
You will install nginx on an Ubuntu lab VM, break it on purpose three ways, and use one triage checklist to find each problem: is the process running, is the port listening, what do the logs say, is there disk, memory and CPU. You will also practise the spoken answer for "app is slow" and "server out of disk".
What: every term in plain English
- Triage — Quick checks in a fixed order to find where the problem is.
- systemctl — The tool to start, stop and check services on modern Linux.
- journalctl — Reads the system logs collected by systemd.
- ss — Shows which ports are open and which program owns them. Newer than netstat.
- df -h — Shows free disk space per filesystem in human sizes.
- du — Shows how much space folders use, to find the big one.
- Load average — Average number of tasks waiting for CPU over 1, 5 and 15 minutes.
- OOM killer — The Linux part that kills a process when memory runs out.
How: step by step
-
Install nginx
sudo apt-get update -qq && sudo apt-get install -y -qq nginxWhat it does: Our test website.
Output
Setting up nginx (1.24.0-2ubuntu7) ... -
Check it works
curl -sI localhost | head -1What it does: 200 means the site is up.
Output
HTTP/1.1 200 OK -
Break 1: stop the service
sudo systemctl stop nginxWhat it does: Like a crash.
Output
(no output) -
Triage step 1: is the service running?
systemctl status nginx --no-pager | head -3What it does: Active: inactive means it is stopped.
Output
○ nginx.service - A high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled) Active: inactive (dead) -
Triage step 2: is the port listening?
sudo ss -ltnp | grep :80 || echo "nothing on 80"What it does: No line means nobody is serving the site.
Output
nothing on 80 -
Triage step 3: read the logs
sudo journalctl -u nginx -n 5 --no-pagerWhat it does: Shows why it stopped. Here it was stopped by a person.
Output
Oct 25 10:02:11 lab systemd[1]: Stopping nginx.service... Oct 25 10:02:11 lab systemd[1]: nginx.service: Deactivated successfully. -
Fix and confirm
sudo systemctl start nginx && curl -sI localhost | head -1What it does: Start it and test again from the server.
Output
HTTP/1.1 200 OK
Example 1: Break 2: the port is taken by another program
Stack. Ubuntu, nginx
Goal. Break 2: the port is taken by another program.
Commands
sudo systemctl stop nginx
sudo python3 -m http.server 80 & # a stranger takes port 80
sudo systemctl start nginx # fails
sudo journalctl -u nginx -n 3 --no-pager
sudo ss -ltnp | grep :80 # who owns the port?
sudo kill %1 # stop the stranger
sudo systemctl start nginx && curl -sI localhost | head -1
What each line does
python3 -m http.server 80— Starts a tiny web server on port 80 to make a clash.journalctl -u nginx— Shows the real error message from nginx.ss -ltnp— l = listening, t = TCP, n = numbers, p = program name.kill %1— Stops background job 1, our fake stranger.
Green output
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
LISTEN 0 5 0.0.0.0:80 0.0.0.0:* users:(("python3",pid=4121,fd=3))
HTTP/1.1 200 OK
Expected result. You found the owner of the port by name and PID. Interview line: Address already in use means check ss -ltnp.
Example 2: Break 3: the disk is full
Stack. Ubuntu
Goal. Break 3: the disk is full.
Commands
df -h / # how full?
sudo fallocate -l 2G /var/log/huge.log # fake a giant log
df -h /
sudo du -xh /var --max-depth=2 | sort -rh | head -5 # find the big folder
ls -lh /var/log/huge.log
sudo truncate -s 0 /var/log/huge.log # empty it, keep the file
sudo rm /var/log/huge.log
df -h /
What each line does
df -h /— Use% near 100 percent means trouble. Apps cannot write files or logs.fallocate -l 2G— Makes a 2 GB file fast, to fake a log explosion.du -xh ... | sort -rh— Lists the biggest folders first.truncate -s 0— Empties a file that a program still has open. Safer than rm for live logs.Prevention— logrotate, CloudWatch disk alarm at 80 percent, bigger EBS volume if needed.
Green output
Filesystem Size Used Avail Use% Mounted on
/dev/root 8.0G 3.1G 4.9G 39% /
/dev/root 8.0G 5.1G 2.9G 64% /
2.1G /var/log
2.0G /var/log/huge.log
/dev/root 8.0G 3.1G 4.9G 39% /
Expected result. You found and freed the space in under a minute. Then you say how you would stop it happening again.
Example 3: Whiteboard: "The app is slow, not down
Stack. Ubuntu
Goal. Whiteboard: "The app is slow, not down."
Commands in order
uptime # load average vs CPU count
nproc # how many CPUs
top -b -n1 | head -15 # who uses CPU and memory
free -h # memory and swap
sudo dmesg -T | grep -i oom | tail -3 # was something killed?
iostat -x 1 3 # disk busy? (apt install sysstat)
curl -o /dev/null -s -w "%{time_total}\n" localhost # response time
What you say
1. Load 7.8 on a 2 CPU box. CPU is the bottleneck.
2. top shows java at 190 percent CPU.
3. free shows no swap use, so memory is fine.
4. Logs show a report job started at 10:00.
5. Short fix: move the job to night time or a separate worker.
6. Long fix: alert on CPU over 80 percent for 10 minutes.
What each line does
uptime— Load higher than CPU count means tasks are waiting.top -b -n1— One snapshot of top, easy to paste.free -h— Shows used, free and swap memory.dmesg ... oom— Shows if the kernel killed a process for memory.curl -w time_total— Measures how slow the page really is, in seconds.
Green output
10:14:02 up 12 days, load average: 7.81, 7.40, 6.95
2
PID USER %CPU %MEM COMMAND
2210 app 190.0 41.2 java
0.000s ... 2.913
Expected result. A slow app answer that moves from symptom to number to cause to fix.
Verify: did it work?
-
Final health check
systemctl is-active nginx && curl -s -o /dev/null -w "%{http_code}\n" localhostWhat it does: Both must pass.
Output
active 200 -
Disk is back to normal
df -h / | tail -1What it does: Use% back to the normal value.
Output
/dev/root 8.0G 3.1G 4.9G 39% /
When it is red 1
Job for nginx.service failed because the control process exited with error code.
Cause. The config is broken or the port is taken.
Fix, step by step
- sudo nginx -t to test the config.
- sudo journalctl -u nginx -n 20 to read the reason.
- Fix the line it names, then start again.
When it is red 2
No space left on device
Cause. Disk is 100 percent full.
Fix, step by step
- df -h to confirm.
- du to find the big folder.
- truncate or delete old logs, then add logrotate and an alarm.
When it is red 3
curl: (7) Failed to connect to localhost port 80
Cause. Nothing listens on port 80.
Fix, step by step
- systemctl status nginx
- ss -ltnp | grep :80
- Start the service or fix the port.
Cleanup
-
Remove nginx if not needed
sudo apt-get remove -y -qq nginxWhat it does: Frees port 80 on your lab VM.
Output
Removing nginx ...
Ravindra Bagale's Tip
When a server is down, do not panic. Remember the order: service, port, log, disk, memory, CPU. Say this order out loud.
Server down झाला की घाबरू नका. क्रम लक्षात ठेवा: service, port, log, disk, memory, CPU. हा क्रम मोठ्याने बोला.
Server down हो तो घबराओ मत. क्रम याद रखो: service, port, log, disk, memory, CPU. ये क्रम ज़ोर से बोलो.
Practice tasks
Medium Find a memory hog
Why: OOM questions are common.
What to do: Run stress-ng to use memory and find it with top and free.
- sudo apt-get install -y stress-ng
- stress-ng --vm 1 --vm-bytes 80% -t 30s &
- free -h; top -b -n1 | head
Check: You see stress-ng at the top of memory use.
Hard Break nginx config
Why: Config errors are the most common reason a restart fails.
What to do: Add a typo to /etc/nginx/sites-enabled/default and find it.
- sudo nginx -t
- Read the line number it reports.
- Fix and reload.
Check: nginx -t says syntax is ok.
Easy Say Linux triage in two lines
Why: Interviewers cut you off after 30 seconds. The short version must come first.
What to do: Write a two line answer about Linux triage for a fresher interview.
- Line 1: the problem it solves.
- Line 2: the one command or file you used.
- Say it aloud with a timer.
Check: You finish inside 30 seconds and you name one real command.
Easy Run the commands, not just read them
Why: An interviewer can tell if you only read. Typing the command once gives you the real output to talk about.
What to do: Run every command in the How part of this lesson on your own lab machine.
- Start a small Ubuntu VM, WSL or EC2 t3.micro.
- Run each step and save the output in notes.txt.
- Mark any output that looks different from the lesson.
Check: notes.txt has the real output of every step.
Medium Break it on purpose
Why: You must know the red error by face. In a live round there is no time to read slowly.
What to do: Cause one error from the "When it is red" part of this lesson and fix it.
- Follow the error section.
- Copy the exact message into your notes.
- Write the fix in one line.
Check: You fixed it using only your notes.
Medium Answer in the 4-line shape
Why: A clear shape makes any answer sound senior: Situation, Check, Fix, Prevent.
What to do: Pick one interview question from this lesson and answer in four lines.
- Situation: what broke.
- Check: the command you ran and what it showed.
- Fix: the change you made.
- Prevent: the alert, test or doc you added.
Check: Each of the four lines has a real noun, like a command, a file or a number.
Medium Mock round with a friend
Why: Speaking is a different skill from knowing. Practice it.
What to do: Let a friend ask you three questions from this lesson.
- Friend picks random questions.
- You answer, friend times you.
- Swap and repeat.
Check: You answer all three without saying "I am not sure" twice.
Hard Whiteboard it top to bottom
Why: Many panels say "draw it". A neat top-to-bottom drawing shows you see the whole flow.
What to do: Draw the main flow of this lesson as boxes from top to bottom.
- Start at the user or the trigger.
- Add each hop: server, container, pipeline, tool.
- Write the command you use to check each box beside it.
Check: Every box has one check command next to it.
Hard Write a mini runbook
Why: Good engineers leave notes for the next person. Interviewers love to hear that you do this.
What to do: Write a one page runbook for the main scenario in this lesson.
- Title, symptoms, first 3 checks, fix, how to confirm, how to undo.
Check: A teammate can follow it alone at 2 a.m.
Homework: try at home
Try at home
At home, ask a friend to break your VM in one secret way (stop a service, fill disk, change a port). Fix it in under 5 minutes while saying each check aloud.
Recap
- Use one fixed triage order: service, port, logs, disk, memory, CPU.
- ss -ltnp tells you who owns a port.
- df -h and du find disk problems; truncate live logs.
- For slow apps, compare load with CPU count and check top.
- End every answer with prevention: an alarm or logrotate.
FAQ
Do I need to remember all flags?
No. Remember the tool and the idea. Use --help in the room if allowed.
netstat or ss?
ss is newer and installed by default. Both are fine to mention.
What if I cannot find the bug in time?
Keep saying your checks aloud. Panels grade the process.
Is it ok to reboot?
Only after you collect logs. Reboot hides the cause.
Where are nginx logs?
/var/log/nginx/access.log and error.log.
Interview questions
-
Website down, you have SSH. What do you do?
systemctl status, ss -ltnp for the port, journalctl and app logs, then df -h, free -h and top. Fix, curl to confirm, then add prevention.
-
Disk is full. Steps?
df -h, du to find the big folder, clean or truncate logs, add logrotate and an 80 percent alarm.
-
What is the difference between systemctl start and enable?
start runs it now; enable makes it start at boot.
-
How do you check if a port is open from another machine?
nc -zv HOST PORT or curl, and check the security group or firewall.
-
What is a zombie process?
A finished child process whose parent has not read its exit status. Usually harmless; fix the parent.
-
How do you find which process uses the most memory?
top sorted by memory, or ps aux --sort=-%mem | head.
Quick quiz
Q1. First command when a service is down?
systemctl status SERVICE.
Q2. How do you see who uses port 80?
sudo ss -ltnp | grep :80
Q3. What shows free disk space?
df -h
Q4. Why truncate instead of rm on a live log?
The program still holds the file open; rm does not free space until it closes.
Q5. What does load average 8 on 2 CPUs mean?
CPU is overloaded; tasks are waiting.
Did you understand? Let us try it once more.
Revision card
Interview card