Unix Tech Interview Questions Flashcards

1
Q

What are Load Averages?

A

Refers to the number of processes which are either currently being executed by the CPU or are waiting for execution. For example: An Idle system has a load of 0 with each process that is being executed or is on the waitlist, the load increase by 1.

You can find this by using $ uptime command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are process states?

A

There are five Linux process states. They are as follows: running & runnable, interruptable_sleep, uninterruptable_sleep, stopped, and zombie

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is PID/PPID and what do they mean?

A
  1. PID stands for Process ID, Which means Identification Number for currently running process in Memory.
  2. PPID stands for Parent Process ID, Which means Parent Process is the responsible for creating the current process(Child Process). Through Parent Process, The child process will be created. If you kill the parent process, the child process is also killed as well
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Unix Console?

A

A unix is an operating system therefore a unix console is the physical hardware? This could be the actual terminal emulator in the UNIX OS. One of the reasons why we use it is because it is faster than using the GUI. A good reason to use it would be from simply creating files, directories, folders, and checking CPU process, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is this command: $ uptime

A

This is a quick way to view the load averages, which indicate the number of tasks (processes) wanting torun. On Linux systems, these numbers include processes wanting to run on CPU, as well as processesblocked in uninterruptible I/O (usually disk I/O). This gives a high level idea of resource load (or demand), butcan’t be properly understood without other tools. Worth a quick look only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is this command: $ dmesg | tail

A

This views the last 10 system messages, if there are any. Look for errors that can cause performanceissues. The example above includes the oom­killer, and TCP dropping a request. Don’t miss this step! dmesg is always worth checking.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is this command: $ vmstat

A

Short for virtual memory stat, vmstat(8) is a commonly available tool (first created for BSD decades ago). It prints a summary of key server statistics on each line. vmstat was run with an argument of 1, to print one second summaries. The first line of output (in this versionof vmstat) has some columns that show the average since boot, instead of the previous second. For now, skip the first line, unless you want to learn and remember which column is which. Columns to check:r: Number of processes running on CPU and waiting for a turn. This provides a better signal than load averages for determining CPU saturation, as it does not include I/O. To interpret: an “r” value greater than the CPU count is saturation.free: Free memory in kilobytes. If there are too many digits to count, you have enough freememory. The “free ­m” command, included as command 7, better explains the state of freememory.si, so: Swap­ins and swap­outs. If these are non­zero, you’re out of memory.us, sy, id, wa, st: These are breakdowns of CPU time, on average across all CPUs. They areuser time, system time (kernel), idle, wait I/O, and stolen time (by other guests, or with Xen, theguest’s own isolated driver domain).The CPU time breakdowns will confirm if the CPUs are busy, by adding user + system time. A constantdegree of wait I/O points to a disk bottleneck; this is where the CPUs are idle, because tasks are blockedwaiting for pending disk I/O. You can treat wait I/O as another form of CPU idle, one that gives a clue as towhy they are idle. System time is necessary for I/O processing. A high system time average, over 20%, can be interesting toexplore further: perhaps the kernel is processing the I/O inefficiently. In the above example, CPU time is almost entirely in user­level, pointing to application level usage instead.The CPUs are also well over 90% utilized on average. This isn’t necessarily a problem; check for the degreeof saturation using the “r” column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is this command: $ mpstat -P ALL 1

A

This command prints CPU time breakdowns per CPU, which can be used to check for an imbalance. Asingle hot CPU can be evidence of a single­threaded application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is this command: $ pidstat

A

Pidstat is a little like top’s per­process summary, but prints a rolling summary instead of clearing the screen.This can be useful for watching patterns over time, and also recording what you saw (copy­n­paste) into arecord of your investigation. The above example identifies two java processes as responsible for consuming CPU. The %CPU column isthe total across all CPUs; 1591% shows that that java processes is consuming almost 16 CPUs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is this command: $ iostat -xz 1

A

This is a great tool for understanding block devices (disks), both the workload applied and the resultingperformance. Look for: r/s, w/s, rkB/s, wkB/s: These are the delivered reads, writes, read Kbytes, and write Kbytes persecond to the device. Use these for workload characterization. A performance problem maysimply be due to an excessive load applied.await: The average time for the I/O in milliseconds. This is the time that the application suffers,as it includes both time queued and time being serviced. Larger than expected average times canbe an indicator of device saturation, or device problems.avgqu­sz: The average number of requests issued to the device. Values greater than 1 can beevidence of saturation (although devices can typically operate on requests in parallel, especiallyvirtual devices which front multiple back­end disks.)%util: Device utilization. This is really a busy percent, showing the time each second that thedevice was doing work. Values greater than 60% typically lead to poor performance (whichshould be seen in await), although it depends on the device. Values close to 100% usuallyindicate saturation.If the storage device is a logical disk device fronting many back­end disks, then 100% utilization may justmean that some I/O is being processed 100% of the time, however, the back­end disks may be far fromsaturated, and may be able to handle much more work. Bear in mind that poor performing disk I/O isn’t necessarily an application issue. Many techniques are typically used to perform I/O asynchronously, so that the application doesn’t block and suffer the latencydirectly (e.g., read­ahead for reads, and buffering for writes).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is this command: $ free -m

A

The right two columns show:buffers: For the buffer cache, used for block device I/O.cached: For the page cache, used by file systems.We just want to check that these aren’t near­zero in size, which can lead to higher disk I/O (confirm usingiostat), and worse performance. The above example looks fine, with many Mbytes in each. The “­/+ buffers/cache” provides less confusing values for used and free memory. Linux uses free memoryfor the caches, but can reclaim it quickly if applications need it. So in a way the cached memory should beincluded in the free memory column, which this line does. There’s even a website, linuxatemyram, about thisconfusion. It can be additionally confusing if ZFS on Linux is used, as we do for some services, as ZFS has its own filesystem cache that isn’t reflected properly by the free ­m columns. It can appear that the system is low onfree memory, when that memory is in fact available for use from the ZFS cache as needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is this command: $ sar -n DEV

A

Use this tool to check network interface throughput: rxkB/s and txkB/s, as a measure of workload, and alsoto check if any limit has been reached. In the above example, eth0 receive is reaching 22 Mbytes/s, which is176 Mbits/sec (well under, say, a 1 Gbit/sec limit). This version also has %ifutil for device utilization (max of both directions for full duplex), which is somethingwe also use Brendan’s nicstat tool to measure. And like with nicstat, this is hard to get right, and seems tonot be working in this example (0.00)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is this command: $ sar -n TCP,ETCP 1

A

This is a summarized view of some key TCP metrics. These include:
Older PostHomePosted by Brendan Gregg at 1:38 PMLabels: linux, performanceactive/s: Number of locally­initiated TCP connections per second (e.g., via connect()).passive/s: Number of remotely­initiated TCP connections per second (e.g., via accept()).retrans/s: Number of TCP retransmits per second.The active and passive counts are often useful as a rough measure of server load: number of new acceptedconnections (passive), and number of downstream connections (active). It might help to think of active asoutbound, and passive as inbound, but this isn’t strictly true (e.g., consider a localhost to localhostconnection). Retransmits are a sign of a network or server issue; it may be an unreliable network (e.g., the publicInternet), or it may be due a server being overloaded and dropping packets. The example above shows justone new TCP connection per­second.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is command : $ top? How is it used?

A

top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it will open an interactive command mode where the top half portion will contain the statistics of processes and resource usage. And Lower half contains a list of the currently running processes.

PID: Shows task’s unique process id.
PR: The process’s priority. The lower the number, the higher the priority.
VIRT: Total virtual memory used by the task.
USER: User name of owner of task.
%CPU: Represents the CPU usage.
TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
SHR: Represents the Shared Memory size (kb) used by a task.
NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
%MEM: Shows the Memory usage of task.
RES: How much physical RAM the process is using, measured in kilobytes.
COMMAND: The name of the command that started the process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is syslog? What/where is it? How is it used?

A

Syslog is a protocol and utility for capturing and logging system information.

Syslog stands for System Logging Protocol and is a standard protocol used to send system log or event messages to a specific server, called a syslog server. It is primarily used to collect various device logs from several different machines in a central location for monitoring and review.

Syslog is one of the most important logs contained in /var/log. This particular log file logs everything except auth-related messages. Say you want to view the contents of that particular log file. To do that, you could quickly issue the command less /var/log/syslog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a file system and what are the standard Unix file systems?

A

A unix file system is made up of files, these files are organized into directories and these directories are organized into a tree-like structure called a file system. Files in Unix System are organized into multi-level hierarchy structure known as a directory tree. At the very top of the file system is a directory called root “/”.

17
Q

What types of files live in a Unix System?

A

Classification of Unix File System:
- Ordinary files
- Directories
- Special files
- Pipes
- Sockets
- Symbolic Links

18
Q

What is a Kernel?

A

The Linux® kernel is the main component of a Linux operating system (OS) and is the core interface between a computer’s hardware and its processes. It communicates between the 2, managing resources as efficiently as possible.

The kernel is so named because—like a seed inside a hard shell—it exists within the OS and controls all the major functions of the hardware, whether it’s a phone, laptop, server, or any other kind of computer.

19
Q

What does a Kernel do?

A

The kernel has 4 jobs:

Memory management: Keep track of how much memory is used to store what, and where

Process management: Determine which processes can use the central processing unit (CPU), when, and for how long
Device drivers: Act as mediator/interpreter between the hardware and processes
System calls and security: Receive requests for service from the processes

20
Q

How do you boot into a different kernel? Why would you do that? How do you know what kernel you are running?

A

You can manually choose which kernel on the GRUB screen at time of boot. You would do that in a scenario where your kernel was updated and not functioning right. You can find which kernel version by running $ uname -f

21
Q

If you had a Unix server that crashed, what would your process be for (1) bringing it back online and (2) trying to identify the reason for the crash.

A

First check to see if the server is powered on, if so, reboot, if not, plug it in. I would start identifing the issue at /car/log/syslog and find the first log message after the reboot. Go through other logs in var/log to find any logs with a time stamp between last log line and before the crash and the first form after.