CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / System Information / uptime

uptime

How long the system has run, and its load average

Beginneressentialperformancemonitoring

uptime prints one line: the time, how long since boot, how many users are logged in, and the 1, 5 and 15-minute load averages. Load average is the number of tasks running or waiting (for CPU or for disk), so you compare it with the CPU count and watch its trend.

Syntaxuptime [-p] [-s]

Watch it run

Users report the site is slow. uptime is the first, cheapest look at the box.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
uptime

Up for a day and 2 hours (no recent reboot), one user logged in. The load averages over 1, 5 and 15 minutes are rising: 3.84 now versus 1.12 a quarter of an hour ago. Something started recently.

Anatomy of a command

$
commanduptime

procps-ng uptime: reads /proc/uptime and /proc/loadavg and counts logged-in users.

How it works

The time since boot comes from /proc/uptime (seconds since boot, plus total idle seconds summed over all CPUs). The user count comes from the login records in utmp (or systemd-logind). The load averages come from /proc/loadavg. Every 5 seconds the kernel counts tasks that are runnable (R: running or waiting for a CPU) plus tasks in uninterruptible sleep (D: usually waiting on disk or NFS), and folds that number into three exponentially damped moving averages with 1, 5 and 15-minute time constants. So a load of 4.0 on a 4-CPU box means on average 4 tasks wanted to run: fully busy, nobody queueing. Load 8 means tasks waited about as long as they ran. Because D-state tasks count, Linux load can be high while the CPUs are idle; that points to I/O, not CPU.

Every 5 seconds the kernel counts running and disk-waiting tasks and folds the count into 1, 5 and 15-minute averages.

scheduledcount Rcount DRun queueR: run or wait4 runnableDisk waitD: blocked I/O4 CPUsnproc = 4Load samplerevery 5 s1-min avgreacts fast5-min avgsmoother15-min avgthe trend
1/7
Tasks that want a CPU

Runnable tasks (state R) are either on a CPU or queued for one. With 4 CPUs, up to 4 run at once and the rest wait.

← → to step

Options you'll actually use

(none)Time, uptime, users and 1/5/15-minute load averages
-pPretty: 'up 1 day, 2 hours, 16 minutes'
-sBoot time as YYYY-MM-DD HH:MM:SS
/proc/loadavgRaw: 3 averages, running/total tasks, last PID
/proc/uptimeRaw: seconds since boot, idle seconds (all CPUs)
wSame header line, plus who is logged in and what they run

Common mistakes

Treating load 8 as bad on every server

Load is a count of tasks. Load 8 on a 32-CPU box is light; on a 2-CPU box it is a queue four times its capacity.

Divide by nproc: sustained values above 1 per CPU mean queueing
Adding CPUs because load is high

On Linux, tasks blocked on disk or NFS (D state) count towards load. If CPUs are idle, more CPUs won't help.

Check top's wa and ps for D-state tasks; look at iostat -x
Reacting to a single high 1-minute value

The 1-minute average jumps on short bursts like cron jobs and deploys.

Compare with the 5 and 15-minute values and watch the trend

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show when the system booted and how long ago, in words.

  2. 2

    Print the load average divided by the number of CPUs (1-minute value).

  3. 3

    Count how many processes are currently in each state (R, S, D, ...).

Related commands

topWatch CPU, memory and processes livevmstatReport CPU, memory, swap and I/O activity over timewShow who is logged in and what they're doinglscpuShow CPU architecture, cores, threads and caches
PreviousfreeNextvmstat
Linux / System Information / uptime

uptime

How long the system has run, and its load average

Beginneressentialperformancemonitoring

uptime prints one line: the time, how long since boot, how many users are logged in, and the 1, 5 and 15-minute load averages. Load average is the number of tasks running or waiting (for CPU or for disk), so you compare it with the CPU count and watch its trend.

Syntaxuptime [-p] [-s]

Watch it run

Users report the site is slow. uptime is the first, cheapest look at the box.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
uptime

Up for a day and 2 hours (no recent reboot), one user logged in. The load averages over 1, 5 and 15 minutes are rising: 3.84 now versus 1.12 a quarter of an hour ago. Something started recently.

Anatomy of a command

$
commanduptime

procps-ng uptime: reads /proc/uptime and /proc/loadavg and counts logged-in users.

How it works

The time since boot comes from /proc/uptime (seconds since boot, plus total idle seconds summed over all CPUs). The user count comes from the login records in utmp (or systemd-logind). The load averages come from /proc/loadavg. Every 5 seconds the kernel counts tasks that are runnable (R: running or waiting for a CPU) plus tasks in uninterruptible sleep (D: usually waiting on disk or NFS), and folds that number into three exponentially damped moving averages with 1, 5 and 15-minute time constants. So a load of 4.0 on a 4-CPU box means on average 4 tasks wanted to run: fully busy, nobody queueing. Load 8 means tasks waited about as long as they ran. Because D-state tasks count, Linux load can be high while the CPUs are idle; that points to I/O, not CPU.

Every 5 seconds the kernel counts running and disk-waiting tasks and folds the count into 1, 5 and 15-minute averages.

scheduledcount Rcount DRun queueR: run or wait4 runnableDisk waitD: blocked I/O4 CPUsnproc = 4Load samplerevery 5 s1-min avgreacts fast5-min avgsmoother15-min avgthe trend
1/7
Tasks that want a CPU

Runnable tasks (state R) are either on a CPU or queued for one. With 4 CPUs, up to 4 run at once and the rest wait.

← → to step

Options you'll actually use

(none)Time, uptime, users and 1/5/15-minute load averages
-pPretty: 'up 1 day, 2 hours, 16 minutes'
-sBoot time as YYYY-MM-DD HH:MM:SS
/proc/loadavgRaw: 3 averages, running/total tasks, last PID
/proc/uptimeRaw: seconds since boot, idle seconds (all CPUs)
wSame header line, plus who is logged in and what they run

Common mistakes

Treating load 8 as bad on every server

Load is a count of tasks. Load 8 on a 32-CPU box is light; on a 2-CPU box it is a queue four times its capacity.

Divide by nproc: sustained values above 1 per CPU mean queueing
Adding CPUs because load is high

On Linux, tasks blocked on disk or NFS (D state) count towards load. If CPUs are idle, more CPUs won't help.

Check top's wa and ps for D-state tasks; look at iostat -x
Reacting to a single high 1-minute value

The 1-minute average jumps on short bursts like cron jobs and deploys.

Compare with the 5 and 15-minute values and watch the trend

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show when the system booted and how long ago, in words.

  2. 2

    Print the load average divided by the number of CPUs (1-minute value).

  3. 3

    Count how many processes are currently in each state (R, S, D, ...).

Related commands

topWatch CPU, memory and processes livevmstatReport CPU, memory, swap and I/O activity over timewShow who is logged in and what they're doinglscpuShow CPU architecture, cores, threads and caches
PreviousfreeNextvmstat