* OS overview (quiz answers) # Where is the "elevator algorithm" typically used? When scheduling I/O requests to a mechanical disk (HDD), reorder them based on LBA (logical block address) so don't have to move the disk head too much; disk head "sweeps" from one side to the other side of the disk, reading/writing data along the way. More efficient. # What resource does a process in "READY" (or "RUNNABLE") state waiting for? Process scheduler, runs each process for a short time slice (quanta), then the next process, and the next, etc. A common alg is "round robin". Scheduler keeps process states: 1. RUNNING: currently running on the CPU. 2. READY: wait for CPU (wait for your turn). 3. WAITING/SLEEPING: wait for I/O (disk, network, peripherals). Can be very long. Running->Ready: - process time slice is over - process can also "yield() to the scheduler", possible. Ready->Running: - scheduler picked up from queue to run next (it's your time) Running->Waiting: - processes requests some I/O (net, disk, etc.), expected to wait longer. - process can become waiting before its time slice ended Waiting->Ready: - scheduler does NOT take you out of wait state - an (I/O) interrupt, runs interrupt handler (software), which'd ID the waiting process, and move it (wakeup) to Ready state. - key: someone OTHER than schedule has to wake process up, else wait forever - woken up process not running right away, but next time scheduler picks you up. Waiting->Running: - possible, but rare (maybe no one in ready state, or highest priority) - better to separate domains of schedulers and interrupts Ready->Waiting: - makes no sense. Process was waiting for CPU not I/O. # Name at least three pieces of data that go into an inode? inode? files, file systems. Contains info about a file. that info is "meta-data". such as - file size - create date, modification date, other timestamps - permissions - file type - info about where the actual file data is (e.g., pointers) File name is not part of inode, but can be considered meta-meta-data (data about the inode itself): the name is part of the "namespace" of the entire file system and maps name(s) to inodes (which then map to actual file data). # What does the "MMU" do? MMU: memory management unit - translate virtual to physical addresses - verifies memory access based on page protection flags: e.g., Read, Write, eXecute - sits b/t CPU and (physical) memory - translations can happen in s/w, but will be too slow (each CPU instruction could need translation). MMU does this in real-time (mem bus speeds). 1. What happens if user process tries to access a vaddr, and MMU can't find a mapping for that vaddr? Process is stopped, gets a segmentation violation signal (SIGSEGV) b/c of a page fault/violation. OS will core dump the process and its mem state for later debugging (e.g., using gdb). 2. If violate page protection flags -> SEGV/core. Process segments: - TEXT seg (bin. instrux) - constants, statics (const int = 17; const char *s = "hello";) - HEAP (malloc) - STACK (stack frames, local var., etc.0 e.g., constants go to a Read-only seg. TEXT segment is marked as Read-only + eXecutable - Program Counter (PC) reg. must point to a segment with "X" bit - to catch buff overflows and other bugs, can set a segment to PROT_NONE (no R, W, or X). The any access -> SEGV. # Who uses the buffer cache? cache: - a copy of a subset of data from one slower location to another faster location - any copy of data: how to keep the copies in sync? - what happens if cache is newer (dirty buf flush) - what happens if source data is changed (via 3rd party, shared data): stale cache. buffer cache: stores data from I/O devices (e.g., disk blocks) page cache: caches process pages from all segments - some segments are readonly, some writeable - incl. data from disk if disk data is cached in both page and buf caches, wastes space. most modern OSs integrate the bufcache into the pagecache # What is a "context switch"? # What is a "system call"? # What does the "two hand-clock" refer to? # What does the unlink(2) system call? # What does the ln -s command do? # What does this command do: gcc -W main.c -o bar -lssl