Unix/Linux Environment — Top 150 Interview Q&A


Basic Commands & Shell

Q1: What is the difference between > and >> in shell redirection?

Answer: > truncates (overwrites) the target file before writing. >> appends to the file. Example:

Q2: How do you redirect both stdout and stderr to a file?

Answer:

2>&1 redirects file descriptor 2 (stderr) to wherever fd 1 (stdout) currently points.

Q3: What does set -e do in a bash script?

Answer: Causes the script to exit immediately if any command returns a non-zero exit status. Often combined with set -u (treat unset variables as errors) and set -o pipefail (fail if any command in a pipeline fails).

Q4: Explain the difference between single quotes and double quotes in bash.

Answer: Single quotes (') preserve every character literally — no variable expansion or escape sequences. Double quotes (") allow variable expansion ($VAR), command substitution (`cmd` or $(cmd)), and escape sequences (\n, \\).

Q5: What is a subshell, and when is one created?

Answer: A subshell is a child process that inherits the parent shell's environment but changes to variables or cd do not affect the parent. Created by: (cmd) grouping, command substitution $(cmd), pipelines (each pipeline element may run in a subshell), and backgrounded jobs.

Q6: How does exec differ from running a command normally?

Answer: exec replaces the current shell process with the given program — no new process is forked. The PID stays the same. If used inside a script, the script process is replaced and code after exec never runs (unless exec fails).

Q7: What is the purpose of /dev/null?

Answer: /dev/null is a special device file that discards all data written to it and returns EOF when read. Used to suppress output: cmd > /dev/null 2>&1.

Q8: How do you find all files modified in the last 24 hours?

-mtime -1 means modified less than 1×24h ago. -mtime +1 means more than 1 day ago.

Q9: Explain xargs and give a practical example.

Answer: xargs reads items from stdin (delimited by whitespace/newlines) and executes a command with those items as arguments. Useful when a command doesn't accept stdin directly.

Q10: What does tee do?

Answer: Reads stdin and writes to both stdout and one or more files simultaneously. Useful for logging while still seeing output:

Q11: What is the difference between which, type, and whereis?

Answer:

Q12: How do you check the exit status of the last command?

Answer: $? holds the exit status (0 = success, non-zero = failure). In pipelines, ${PIPESTATUS[@]} holds per-command statuses.

Q13: What is $@ vs $* in bash?

Answer: Both expand to all positional parameters, but "$@" preserves individual argument boundaries (each arg quoted separately), while "$*" joins them with the first char of IFS. Use "$@" when passing arguments through.

Q14: How do you create a here-document?

<<-EOF strips leading tabs (useful for indented scripts). <<'EOF' suppresses variable expansion.

Q15: What is the difference between [ ] and [[ ]] in bash conditionals?

Answer: [ ] is the POSIX test command — limited operators, word splitting applies. [[ ]] is a bash keyword — supports regex (=~), pattern matching, &&/|| without quoting issues, and no word splitting.


Process Management

Q16: What is a process in Linux?

Answer: A process is a running instance of a program. It has a unique PID, its own virtual address space, file descriptors, credentials (UID/GID), and associated kernel data structures (task_struct). Processes are created via fork() and execute programs via exec().

Q17: What is the difference between a process and a thread?

Answer: Threads (lightweight processes) share the same virtual address space, file descriptors, and signal handlers as their parent process. Separate processes have independent address spaces. In Linux, both are implemented via clone() with different flag combinations. Threads share mm_struct; processes get a copy-on-write clone.

Q18: Explain the process lifecycle (states).

Answer:

Q19: What is a zombie process and how do you remove it?

Answer: A zombie is a process that has exited but whose parent hasn't called wait() to collect its exit status. It consumes a PID and a minimal task_struct entry. To remove: send SIGCHLD to the parent (to trigger wait()), or kill the parent (init/systemd will reparent and reap). You cannot kill a zombie directly.

Q20: What is an orphan process?

Answer: A process whose parent has exited before it. Linux reparents orphans to PID 1 (init/systemd), which periodically calls wait() to reap them.

Q21: How does fork() work?

Answer: fork() creates a child process by copying the parent's address space (using copy-on-write). The child gets a new PID and its own file descriptor table (sharing the underlying open file descriptions). fork() returns 0 in the child and the child's PID in the parent (or -1 on failure).

Q22: What is copy-on-write (COW) in the context of fork?

Answer: After fork(), parent and child share the same physical pages, marked read-only. When either process writes to a page, the kernel makes a private copy for the writer. This avoids copying the entire address space upfront, making fork()+exec() efficient.

Q23: How do you send a signal to a process?

Q24: What is the difference between SIGTERM and SIGKILL?

Answer: SIGTERM (15) is a polite termination request — the process can catch it, clean up, and exit gracefully. SIGKILL (9) is sent directly to the kernel; the process cannot catch, block, or ignore it. The kernel forcibly terminates it. Always try SIGTERM first.

Q25: What signals can a process not catch or ignore?

Answer: SIGKILL (9) and SIGSTOP (19) cannot be caught, blocked, or ignored — they are handled directly by the kernel.

Q26: What is a process group and a session?

Answer: A process group is a collection of processes, typically a pipeline. The process group leader has the same PGID as its PID. A session groups process groups, created by setsid(). The session leader's SID equals its PID. Terminal signals (Ctrl+C → SIGINT) are sent to the foreground process group of the controlling terminal.

Q27: How do you run a process in the background and bring it to the foreground?

Q28: How does nohup work?

Answer: nohup runs a command immune to SIGHUP (sent when the controlling terminal closes). It also redirects stdout to nohup.out if stdout is a terminal. Combine with & to detach completely: nohup cmd &.

Q29: What does nice and renice do?

Answer: nice sets the scheduling priority (niceness) when starting a process. Range: -20 (highest priority) to +19 (lowest). renice changes priority of a running process. Only root can set negative niceness.

Q30: How do you list all running processes and their resource usage?

Q31: What is the /proc filesystem?

Answer: /proc is a virtual filesystem (procfs) that exposes kernel data structures as files. /proc/<pid>/ contains per-process info: cmdline, maps (memory maps), fd/ (open file descriptors), status, stat, smaps, environ. /proc/cpuinfo, /proc/meminfo, /proc/net/ expose system-wide info.

Q32: How do you find which process is using a specific port?

Q33: How do you find the parent of a process?

Q34: What is wait() and why is it important?

Answer: wait() (and waitpid()) is a system call that blocks the parent until a child terminates, then retrieves the child's exit status. Without it, children become zombies. In shells, wait is also a built-in that waits for background jobs.

Q35: Explain exec() family of calls.

Answer: exec() replaces the current process image with a new program. Variants: execve(path, argv, envp) (the actual syscall), execvp (searches PATH), execle (explicit env), etc. The PID remains the same. Open file descriptors are inherited unless marked FD_CLOEXEC.


Memory Management

Q36: What is virtual memory?

Answer: Virtual memory gives each process its own isolated address space, larger than physical RAM. The kernel maps virtual pages to physical frames via page tables. Benefits: isolation, ability to use more memory than physically available (swap), simpler program loading, shared libraries via shared mappings.

Q37: What is the difference between physical and virtual addresses?

Answer: A virtual address is what the process sees — it's specific to the process's address space. The MMU (Memory Management Unit) translates it to a physical address using page tables. Multiple processes can have the same virtual address mapping to different physical frames.

Q38: Explain the layout of a process's virtual address space.

Answer: From low to high (typical Linux x86-64):

  1. Text segment — read-only executable code

  2. Data segment — initialized global/static variables

  3. BSS — uninitialized globals (zero-filled)

  4. Heap — grows upward via brk()/mmap()

  5. Memory-mapped region — files, shared libs, anonymous mappings

  6. Stack — grows downward, local variables, return addresses

  7. Kernel space — above the user-space/kernel split (not accessible from user space)

Q39: What is a page fault?

Answer: Occurs when a process accesses a virtual address not currently mapped to a physical frame. The CPU raises an exception, the kernel's page fault handler runs, and either:

Q40: What is the difference between malloc and mmap for memory allocation?

Answer: malloc is a C library function that manages a heap (typically via brk()/sbrk() for small allocations or mmap() for large ones). mmap() is a system call that maps files or anonymous memory directly into the address space — used for large allocations, file I/O, and shared memory. mmap gives kernel-managed pages; malloc gives library-managed blocks.

Q41: What is the OOM killer?

Answer: When the kernel cannot satisfy a memory allocation request and swap is exhausted, the Out-Of-Memory killer is invoked. It scores processes (based on memory usage, niceness, runtime) and terminates one to free memory. /proc/<pid>/oom_score shows the score; /proc/<pid>/oom_score_adj adjusts it (-1000 = never kill, +1000 = always kill first).

Q42: What is swap space and how does it work?

Answer: Swap is disk space used to hold pages evicted from RAM when physical memory is low. The kernel's page replacement algorithm (similar to LRU) selects victim pages. Swapping is slow (disk I/O) and degrades performance significantly. swapon/swapoff manage swap partitions/files.

Q43: What is the difference between the stack and the heap?

Answer:

Q44: What is a memory-mapped file?

Answer: mmap() maps a file (or part of it) directly into the process's virtual address space. Reads/writes to that region translate to file I/O managed by the kernel's page cache. Advantages: avoids explicit read/write syscalls, allows multiple processes to share the same file pages, useful for large files and IPC.

Q45: What is the difference between brk() and mmap() for heap management?

Answer: brk()/sbrk() adjusts the program break — the end of the data segment — to grow/shrink the heap contiguously. Efficient for small, sequential allocations. mmap() creates independent memory regions anywhere in the address space — preferred for large allocations (glibc uses mmap for >128KB by default) as it can be independently freed.

Q46: What does ulimit control?

Answer: ulimit sets per-process resource limits enforced by the kernel:

Q47: How do you check memory usage on a Linux system?

Q48: What is the difference between RSS, VSZ, and PSS?

Answer:

Q49: What is huge pages and when would you use them?

Answer: Huge pages (2MB or 1GB on x86-64 vs default 4KB) reduce TLB pressure by covering more memory per TLB entry. Useful for workloads with large working sets (databases, HPC). Configured via /proc/sys/vm/nr_hugepages. Transparent Huge Pages (THP) automatically promote pages; can be configured via /sys/kernel/mm/transparent_hugepage/enabled.

Q50: How does the kernel's slab allocator work?

Answer: The slab allocator (SLUB/SLOB/SLAB) manages kernel memory for frequently allocated objects (inodes, task structs, etc.). It pre-allocates slabs (groups of memory pages) for specific object sizes, avoiding fragmentation and reducing allocation overhead. cat /proc/slabinfo shows slab statistics.


File Permissions & Ownership

Q51: Explain the Unix permission model (rwx).

Answer: Each file has three permission sets: owner (user), group, other. Each set has read (r=4), write (w=2), execute (x=1) bits. For directories: r=list contents, w=create/delete entries, x=traverse (cd into). Example: chmod 755 file = rwxr-xr-x.

Q52: What are setuid, setgid, and sticky bits?

Answer:

Q53: What is the difference between effective UID and real UID?

Answer: The real UID is who you actually are (who launched the process). The effective UID is what the kernel checks for most permission decisions. They differ when a setuid program is running. A process can temporarily drop privileges by changing its effective UID back to real UID.

Q54: How does sudo work internally?

Answer: The sudo binary is setuid root. When invoked, it runs as root (effective UID 0), checks /etc/sudoers to authorize the request, then calls setuid() to become the target user (or stays root) before exec()ing the requested command.

Q55: How do ACLs extend standard Unix permissions?

Answer: POSIX ACLs allow per-user and per-group permissions beyond the owner/group/other model. Managed with getfacl / setfacl. The effective mask limits ACL permissions. Extended attributes store ACL data in the filesystem.


Environment & Shell Internals

Q56: What is the difference between a login shell and a non-login shell?

Answer: A login shell reads /etc/profile and ~/.bash_profile (or ~/.profile). A non-login interactive shell reads ~/.bashrc. A login shell is started when you log in via terminal, SSH, or bash --login. bash -i starts an interactive non-login shell.

Q57: What is the PATH variable and how does the shell use it?

Answer: PATH is a colon-separated list of directories the shell searches for executables when a command is entered without an absolute path. The shell tries each directory left-to-right and uses the first match found. Built-ins and functions are checked before PATH.

Q58: What is the difference between source (.) and executing a script?

Answer: Executing a script (./script.sh) runs it in a subshell — environment changes don't affect the parent. source script.sh (or . script.sh) runs the script in the current shell — variable assignments, cd, and function definitions persist in the current session.

Q59: How do environment variables differ from shell variables?

Answer: Shell variables are local to the current shell process. Environment variables are exported (export VAR) and inherited by child processes. Use env or printenv to list environment variables; set lists all shell variables.

Q60: What happens when you type a command in bash?

Answer: (1) Tokenization & parsing. (2) Alias expansion. (3) Command type check: function → built-in → hashed path → PATH search. (4) Variable/glob/brace expansion. (5) fork() + exec() (for external commands), or direct execution (for built-ins). (6) Parent shell waits for child (foreground) or continues (background).


Signals

Q61: What are signals in Unix?

Answer: Signals are software interrupts sent to a process to notify it of an event. Defined in <signal.h>. A process can install a handler (sigaction()), ignore a signal, or accept the default action (usually terminate, dump core, stop, or continue).

Q62: List 10 important signals and their default actions.

SignalNumberDefault ActionDescription
SIGHUP1TerminateTerminal hangup / config reload
SIGINT2TerminateCtrl+C
SIGQUIT3Core dumpCtrl+\
SIGILL4Core dumpIllegal instruction
SIGSEGV11Core dumpSegmentation fault
SIGPIPE13TerminateWrite to broken pipe
SIGALRM14TerminateTimer (alarm())
SIGTERM15TerminateGraceful termination request
SIGCHLD17IgnoreChild state changed
SIGSTOP19StopCannot be caught/ignored

Q63: What is signal masking and sigprocmask()?

Answer: A process can block signals using sigprocmask() — blocked signals are not delivered until unblocked. They remain pending. This is used to protect critical sections from asynchronous signal interruption. sigpending() reveals pending signals. Each thread has its own signal mask.

Q64: What is SA_RESTART in sigaction?

Answer: When set, system calls interrupted by the signal are automatically restarted rather than returning EINTR. Without it, programs must handle EINTR from calls like read(), write(), select().

Q65: What is a real-time signal?

Answer: Signals SIGRTMIN–SIGRTMAX (34–64) are real-time signals. Unlike standard signals, they queue (multiple signals of the same number are not merged), carry data (siginfo_t), and are delivered in order of signal number. Used for precise asynchronous notification.


Scheduling

Q66: What is the Linux CFS (Completely Fair Scheduler)?

Answer: CFS is the default Linux scheduler for normal processes. It tracks each process's virtual runtime (vruntime) — the amount of CPU time received, weighted by priority. The process with the smallest vruntime is chosen next. A red-black tree orders runnable processes by vruntime, giving O(log N) pick-next. It aims for proportionally fair CPU allocation.

Q67: What scheduling classes exist in Linux?

Answer:

Q68: What is CPU affinity and how do you set it?

Answer: CPU affinity restricts which CPUs a process/thread may run on.

Via API: sched_setaffinity(). Used for performance (cache locality, NUMA) or isolation.

Q69: What is a context switch?

Answer: A context switch is the kernel saving the running process's CPU state (registers, program counter) and restoring another process's state. Costs: saving/restoring CPU state, TLB flush (if not using PCID), cache invalidation. Triggered by: time slice expiry, blocking syscall, higher-priority task waking up.

Q70: What is chrt used for?


Boot & Init Systems

Q71: Describe the Linux boot process.

Answer:

  1. BIOS/UEFI — firmware initializes hardware, selects boot device.

  2. Bootloader (GRUB) — reads partition, loads kernel image and initrd.

  3. Kernel init — decompresses self, initializes subsystems (memory, drivers), mounts initrd (initramfs).

  4. initramfs — minimal root filesystem; loads drivers, mounts real root.

  5. PID 1 (systemd/init) — first user-space process; starts services.

  6. Runlevel/target — systemd activates units to reach default target (graphical.target or multi-user.target).

Q72: What is systemd and how does it differ from SysV init?

Answer: systemd is a parallel init system using dependency graphs and socket/D-Bus activation to start services concurrently. SysV init uses sequential numbered rc scripts. systemd uses unit files (.service, .socket, .timer); SysV uses shell scripts in /etc/init.d/. systemd tracks processes via cgroups; SysV cannot reliably track spawned children.

Q73: How do you manage systemd services?

Q74: What is initramfs and why is it needed?

Answer: initramfs (initial RAM filesystem) is a temporary root filesystem loaded into memory by the bootloader. It allows the kernel to load drivers (disk controllers, LVM, encrypted volumes) needed to mount the real root filesystem. Once the real root is mounted, the kernel pivot_root() or switch_root() to it.

Q75: What are runlevels in SysV and their systemd equivalents?

RunlevelSysVsystemd target
0Haltpoweroff.target
1Single-userrescue.target
3Multi-user, no GUImulti-user.target
5Multi-user, GUIgraphical.target
6Rebootreboot.target

Networking Basics

Q76: What is the difference between TCP and UDP?

Answer: TCP is connection-oriented, reliable (retransmission, ordering, flow control), and higher overhead. UDP is connectionless, unreliable (no retransmission, no ordering), lower overhead. TCP: HTTP, SSH, FTP. UDP: DNS, DHCP, video streaming, VoIP.

Q77: How do you check network interface configuration?

Q78: How do you test connectivity between two hosts?

Q79: What does netstat/ss show?

Answer: They display socket/connection state:

Q80: What is iptables / nftables?

Answer: Firewall and packet-filtering frameworks. iptables uses tables (filter, nat, mangle) with chains (INPUT, OUTPUT, FORWARD) and rules matched against packet headers. nftables is its successor with a unified framework and more efficient rule matching. firewalld and ufw are higher-level front-ends.


Advanced Shell & Scripting

Q81: What is a file descriptor?

Answer: An integer index into a per-process table of open files. FD 0 = stdin, 1 = stdout, 2 = stderr. All I/O happens via FDs. open() returns FDs; dup2() duplicates them. /proc/<pid>/fd/ lists open FDs as symlinks.

Q82: How does a pipe work internally?

Answer: A pipe is an in-kernel FIFO buffer (typically 64KB). pipe() syscall creates two FDs: read end and write end. In cmd1 | cmd2, the shell creates a pipe, forks two processes: cmd1 gets the write end as stdout, cmd2 gets the read end as stdin. The kernel buffers data between them.

Q83: What is lsof and what can it tell you?

Tells you: file path, type (REG, DIR, CHR, FIFO, IPv4), FD number, PID, permissions.

Q84: Explain awk in one paragraph.

Answer: awk is a text-processing language that processes input line by line, splitting each into fields ($1, $2, ...) by FS (default: whitespace). Pattern–action pairs run when patterns match. Special patterns: BEGIN (before input), END (after input). Built-in variables: NR (line number), NF (field count), FS, RS (record separator). Example:

Q85: Explain sed usage.

Answer: sed is a stream editor that applies editing commands (substitute, delete, print, append) to each line:

Q86: How do you check if a port is open without telnet?

Q87: What is a named pipe (FIFO)?

Answer: A named pipe is a FIFO with a filesystem entry, created via mkfifo. Unlike anonymous pipes, it can be opened by unrelated processes (by name). Writes block until a reader opens it and vice versa. Used for communication between unrelated processes without a shared parent.

Q88: How do you monitor file changes in real time?

Q89: What is strace and what does it output?

Answer: strace traces system calls and signals made by a process. Output shows: syscall name, arguments, return value. Useful for debugging hangs, file access, permission issues, network calls.

Q90: How do you schedule a one-time job vs. a recurring job?

Answer:


Additional Unix/Linux Concepts

Answer: A hard link is a directory entry pointing directly to an inode — multiple names for the same file data, same inode number, same device. Deleting one leaves data intact until all hard links are removed. Cannot cross filesystems or link directories (usually). A soft link (symlink) is a file containing a path — following it redirects to the target. Can cross filesystems, point to directories, and dangle (target deleted).

Q92: What is an inode?

Answer: An inode is a data structure storing file metadata: permissions, owner/group, size, timestamps (atime, mtime, ctime), link count, and pointers to data blocks. Does NOT store the filename — that's in the directory entry. Every file and directory has an inode. stat file displays inode info; ls -i shows inode numbers.

Q93: What are the three timestamps on a file (atime, mtime, ctime)?

Answer:

Q94: What is chroot and what is it used for?

Answer: chroot changes the apparent root directory for a process and its children. Used for: security isolation (jails), system recovery (chroot into a broken system), build environments. Does not provide complete isolation — privileged processes can escape. Containers (namespaces) provide stronger isolation.

Q95: What is /etc/passwd and /etc/shadow?

Answer: /etc/passwd stores user account info (username, UID, GID, home dir, shell) — world-readable. Originally stored password hashes in field 2, now replaced with x. /etc/shadow stores hashed passwords and aging policy — readable only by root. Separation prevents unprivileged users from obtaining hashes for offline cracking.

Q96: What does the mount command do?

Answer: mount attaches a filesystem (on a device or network path) to a directory (mount point) in the VFS tree. After mounting, files are accessible via the mount point. /etc/fstab defines persistent mounts; systemd can also manage mounts via .mount units.

Q97: What is df vs du?

Answer:

Q98: How do you create and manage disk partitions?

Q99: What is LVM and what are its benefits?

Answer: LVM (Logical Volume Manager) abstracts physical storage: Physical Volumes (PVs, e.g., /dev/sdb) → Volume Group (VG) → Logical Volumes (LVs, used as block devices). Benefits: resize volumes without repartitioning, snapshots, spanning across disks, thin provisioning.

Q100: What are cgroups and what are they used for?

Answer: Control Groups (cgroups) limit and monitor resource usage (CPU, memory, I/O, network) for groups of processes. Used by systemd, Docker, Kubernetes to enforce resource limits and accounting. v1 has per-subsystem hierarchies; v2 (unified hierarchy) is the modern standard.

Q101: What is a namespace in Linux?

Answer: Namespaces isolate specific kernel resources per group of processes. Types: PID (process IDs), mount (filesystem view), network (network interfaces), UTS (hostname), IPC (SysV IPC), user (UIDs), cgroup, time. Containers combine multiple namespaces + cgroups for lightweight isolation.

Q102: What is LD_PRELOAD and how can it be used?

Answer: LD_PRELOAD is an environment variable that causes the dynamic linker to load specified shared libraries before all others. Functions in the preloaded library override those in later libraries. Used for: debugging (intercept malloc), testing (mock system calls), performance profiling. Ignored for setuid binaries for security.

Q103: What is the difference between static and dynamic linking?

Answer: Static linking copies all library code into the executable at build time — self-contained, no runtime library dependencies, larger binary. Dynamic linking references shared libraries (.so files) resolved at load time by ld.so — smaller binary, shared memory for library code across processes, but requires libraries at correct paths/versions (ldd shows dependencies).

Q104: How does the dynamic linker (ld.so) find shared libraries?

Answer: Search order: DT_RPATH in ELF (deprecated), LD_LIBRARY_PATH, DT_RUNPATH in ELF, /etc/ld.so.cache (built from /etc/ld.so.conf), default paths (/lib, /usr/lib). Run ldconfig to rebuild the cache after installing libraries.

Q105: What is /proc/sys and how do you use it for tuning?

Answer: /proc/sys/ exposes kernel parameters as files. Read/write them directly or use sysctl:

Persistent: add to /etc/sysctl.conf or /etc/sysctl.d/.

Q106: What is the /sys filesystem (sysfs)?

Answer: sysfs exposes the kernel's device model — devices, drivers, buses — as a virtual filesystem under /sys. Attributes (files) represent device properties and can be read/written to configure hardware. udev uses sysfs events for device management.

Q107: What is dmesg?

Answer: dmesg prints the kernel ring buffer — messages from the kernel during boot and runtime (driver init, hardware errors, OOM events). Limited circular buffer. journalctl -k provides the same via systemd. Useful for diagnosing hardware issues and driver problems.

Q108: How do you add a kernel module?

Q109: What is sar and what can it monitor?

Answer: sar (System Activity Reporter, part of sysstat) collects and reports system performance data: CPU, memory, disk I/O, network, paging, context switches. Data is logged periodically and can be replayed. Examples:

Q110: What is the difference between grep, egrep, and fgrep?

Answer: grep uses basic regular expressions (BRE). egrep (= grep -E) uses extended regular expressions (ERE) — supports +, ?, |, () without backslash. fgrep (= grep -F) treats the pattern as a literal fixed string — fastest, no regex interpretation.

Q111: How does chmod work with octal vs. symbolic notation?

Q112: How do you recursively change ownership?

Q113: What is sudo vs su?

Answer: su switches the current user (requires the target user's password). su - creates a login shell for that user. sudo runs a single command as another user (usually root) after authenticating as yourself, governed by /etc/sudoers. sudo provides better auditability and fine-grained control.

Q114: What are Unix domain sockets?

Answer: IPC mechanism using socket API but communicating within the kernel (no network stack). Faster than TCP loopback. Identified by filesystem path (e.g., /run/docker.sock). Support stream (SOCK_STREAM) and datagram (SOCK_DGRAM) modes. Used by databases, Docker, X11, systemd.

Q115: What is /etc/hosts and how is it used?

Answer: /etc/hosts maps hostnames to IP addresses, consulted before DNS (by default, per /etc/nsswitch.conf). Used for local overrides, testing, or blocking domains. Format: IP hostname alias...

Q116: How do you find large files on a filesystem?

Q117: What is rsync and how does it differ from cp?

Answer: rsync synchronizes files/directories, transferring only differences (delta). Supports remote transfer over SSH (rsync -avz src user@host:/dest), preserves permissions/timestamps/symlinks, resumes interrupted transfers. cp copies entirely each time.

Q118: How do you measure disk I/O performance?

Q119: What is screen / tmux and why use it?

Answer: Terminal multiplexers that keep sessions alive after disconnect. Multiple windows/panes in one terminal. Detach with Ctrl+a d (screen) or Ctrl+b d (tmux), reattach with screen -r / tmux attach. Essential for long-running remote tasks.

Q120: What is cron and how do you configure it?

Answer: cron is a daemon that executes scheduled commands. crontab -e edits per-user crontabs. Syntax: min hour dom month dow command. Special strings: @reboot, @daily, @hourly. System-wide crontabs: /etc/crontab, /etc/cron.d/. Output is emailed unless redirected.

Q121: What is the difference between /tmp and /var/tmp?

Answer: /tmp is cleared on reboot (often mounted as tmpfs in memory). /var/tmp persists across reboots. Applications needing temporary space that survives reboots should use /var/tmp.

Q122: How do you check system uptime and load average?

Load average = average number of runnable + uninterruptible processes over 1, 5, 15 minutes. A load equal to the number of CPUs means fully utilized.

Q123: What does top's display tell you?

Answer: Header: uptime, users, load averages. CPU line: %us (user), %sy (system/kernel), %ni (nice), %id (idle), %wa (iowait), %hi (hardware IRQ), %si (software IRQ), %st (steal, VM). Memory lines: total, free, used, buff/cache, swap. Process list: PID, user, priority, nice, VIRT, RES, SHR, state, %CPU, %MEM, TIME+, command.

Q124: What is ionice used for?

Sets I/O scheduling priority for a process using the CFQ/BFQ scheduler classes: real-time (1), best-effort (2), idle (3).

Q125: What is /proc/interrupts?

Answer: Shows per-CPU interrupt counts for each IRQ line. Useful for diagnosing interrupt affinity issues and IRQ storms. Columns: IRQ number, per-CPU counts, type, device name.

Q126: What is syslog and how does logging work in Linux?

Answer: syslog is a standard logging protocol. Traditionally, syslogd (or rsyslog, syslog-ng) receives log messages from applications (via /dev/log socket or UDP/TCP port 514) and routes them to files/remote hosts based on facility+priority rules. systemd uses journald (binary journal) with journalctl for querying.

Q127: What is /etc/resolv.conf?

Answer: Configures DNS resolver: nameserver lines list DNS servers (up to 3), search sets domain search list, options for timeout/retries. On systems with systemd-resolved or NetworkManager, this file may be a symlink managed automatically.

Q128: How do you check hardware information?

Q129: What is /etc/fstab?

Answer: Defines filesystems to mount at boot. Fields: device, mount point, filesystem type, options, dump (backup), pass (fsck order). Example:

Q130: What is the difference between sync and fsync?

Answer: sync is a command/syscall that flushes all dirty kernel buffers to disk (writes are buffered for performance). fsync(fd) flushes buffers for a specific file to the storage device — needed for durability guarantees (databases). fdatasync() is like fsync but skips metadata updates not needed for data recovery.

Q131: How do you trace library calls (as opposed to system calls)?

Shows calls to libc and other shared library functions, unlike strace which shows kernel boundary calls.

Q132: What is perf used for?

Answer: perf is the Linux performance analysis tool:

Q133: How do you use gdb to debug a crash?

Q134: What is valgrind and when is it useful?

Answer: valgrind is a dynamic analysis tool suite. memcheck (default) detects memory errors: heap overflows, use-after-free, uninitialized reads, memory leaks. massif profiles heap usage. callgrind profiles CPU. Runs programs on a synthetic CPU — significant slowdown (~10–50×). Used in development/testing, not production.

Q135: What is a core dump and how do you enable it?

Answer: A core dump is a file containing the memory image of a process at crash time. Enable:

Analyze with gdb ./binary core. systemd-coredump manages core dumps via coredumpctl.

Q136: What is netcat (nc) used for in system administration?

Q137: What is tcpdump used for?

Q138: What is /dev/random vs /dev/urandom?

Answer: Both provide cryptographically secure random numbers from the kernel's entropy pool. /dev/random blocks when entropy is exhausted (older kernels). /dev/urandom never blocks — it uses the CSPRNG which is safe post-seeding. On modern Linux (≥5.18), both behave identically after boot. Use getrandom() syscall for applications.

Q139: What is watch command?

Q140: How do you check if a kernel parameter change is persistent?

Answer: /proc/sys/ changes are volatile (lost on reboot). Persistent changes go in /etc/sysctl.conf or files under /etc/sysctl.d/. Apply immediately with sysctl -p. Verify: sysctl <key>.

Q141: What are namespaces and how do they enable containerization?

Answer: Linux namespaces create isolated views of kernel resources. A container typically uses: PID namespace (isolated process tree), mount namespace (own filesystem), network namespace (own interfaces/routing), UTS (own hostname), IPC, user (UID mapping). unshare and clone() with flags create new namespaces. The container runtime (Docker/containerd) wires these together.

Q142: What is strace's overhead concern in production?

Answer: strace uses ptrace() which serializes all syscalls through the tracer — can slow a process 2–10×. For production tracing, use bpftrace or perf trace which use eBPF with much lower overhead.

Q143: What is eBPF?

Answer: Extended Berkeley Packet Filter is a safe in-kernel virtual machine that runs user-supplied programs at kernel events (syscalls, tracepoints, kprobes, network packets) without modifying kernel source or loading modules. Used for: observability (bpftrace, bcc tools), networking (XDP), security (seccomp-bpf, Falco). Programs are JIT-compiled and verified for safety.

Q144: What is auditd used for?

Answer: auditd is the Linux audit daemon that records security-relevant events (file access, syscalls, logins, privilege changes) to /var/log/audit/audit.log. Rules set via auditctl. ausearch and aureport query logs. Required for compliance (PCI-DSS, SOX).

Q145: What is the difference between adduser and useradd?

Answer: useradd is the low-level binary (sets specific options). adduser is a higher-level Perl/shell script (Debian/Ubuntu) that calls useradd with sane defaults, creates home directory, sets shell, prompts for password. On RHEL/CentOS, adduser is a symlink to useradd.

Q146: How do you find which package provides a file?

Q147: What is systemd-analyze used for?

Q148: What is journalctl and how do you use it?

Q149: What is the purpose of /etc/sudoers and how do you edit it safely?

Answer: /etc/sudoers defines who can run what as whom with sudo. Always edit with visudo (validates syntax before saving — a syntax error can lock out all sudo access). Key syntax: user host=(runas) command. Includes: %wheel ALL=(ALL) ALL (wheel group gets full sudo), NOPASSWD: for passwordless commands.

Q150: What is a memory leak and how do you detect it in a Linux process?

Answer: A memory leak occurs when allocated memory is never freed, causing the process's memory usage to grow indefinitely. Detection methods: