Summary Flashcards
Process context
Process context : the snapshotted state of a process, which includes its data,
memory utilization, and execution progress. The process context must be saved
when the OS wants to stop running a process, and it gets reloaded when the OS
resumes running the process.
Virtual address
Virtual address: mapped to physical addresses using a data structure called a
“page table”. Creates a consistent format for the OS to manage the memory of all
processes. Includes the heap, stack, code segment, data segment, and kernel
space.
Disk
Disk: magnetic or optical storage for data. Disk storage is slower than your main
memory storage, but is cheaper and stores data even when the computer is
turned off.
File descriptors
File descriptors : used as handles to files by processes
○ STDIN : defaults to keyboard input
○ STDOUT : defaults to printing output on your monitor/terminal
Context switch
Context switch: the OS switches the process being executed. Context switches
begin with a TRAP, which is a set of instructions that cause the computer to
transition from user mode to kernel mode. Next, the OS saves the current
process context in it’s PCB, loads in the context of the next process’s PCB,
resumes this next process, and transitions back to the user mode. Context
switching creates overhead.
Multi-core
Multi-core : a system with multiple CPUs
Process state
Process state: running, blocking, or ready. Each state has its own process
queue in the OS.
○ Running : instructions for this process are being executed by the CPU.
○ Blocked : process is waiting on I/O access, user input, or some other
condition that cannot be met immediately, but is required to continue
executing.
○ Ready : the process has all it needs to run and is waiting for CPU access.
Preemption
Preemption : when a process becomes ready, immediately give it an opportunity
to run, regardless of any processes already running or processes ahead of it in
the ready queue.
OS Scheduler
OS Scheduler: most OSes have a finite time-slice for which processes can run
before they are switched out. Larger time slices reduce the overhead of context
switching, however cause longer wait times for new processes that wish to run.
Prioritization
Prioritization: a technique used in scheduling to ensure that urgent processes
gain “fast passes” to the CPUs. Different priority processes may be placed in
different priority queues. The priority level is an assigned number in a range of
possible values that depends on the OS.
I/O
I/O : refers to any interactions between your computer and external devices, such
as keyboard, mouse, disks, printers, monitors. Linux assigns a unique file
descriptor to each external device.
Bytestream abstraction
Bytestream abstraction: an abstraction in Linux, in which all data is sent to and
read from devices as a sequence of bytes
Write()
Write() : accepts a file descriptor as an input. Returns the number of bytes written
to the location specified by the file descriptor. Variations and additional syntactic
information are specified in the man pages.
○ fwrite() : buffered write
Read()
Read() : accepts a file descriptor as an input. Returns the number of bytes read
from the location specified by the file descriptor. Variations and additional
syntactic information are specified in the man pages.
○ fread() : buffered read
Disk controller
Disk controller: A disk controller is the controller circuit that connects the CPU
with the actual hard disk. The controller typically runs firmware, which is software
written in low-level language that controllers actual hardware. The controller
interacts with the disk device drivers running in the operating system by
sending/receiving data to/from disk to applications.
When Does Context Switching Occur?
(1) Currently running process makes a system call and is blocked
• Process is put on the blocked queue
• Scheduler picks up another process in ready queue to run
• (2) Currently running process terminates
• Scheduler picks up another process in ready queue to run
• (3) Hardware or software interrupt happens
• OS handles the interrupt and blocked processes may become ready
• Scheduler may choose to continue running current process of pick
another process to run
• (4) Current process used up its current “time
• Scheduler picks up another process in ready queue to run
Typical
Scheduler Heuristics
• Each process runs for a fixed time slice (typically 100 msecmsec)
• Response times vs throughput tradeoffs
• Some processes have higher priority over others:
• Interactive applications that block frequently because of system calls
• User -defined priority (using “ nice ” command in Linux or task manager in
Windows)
• System daemons
• User has a higher priority over other users using the computer
State Transitions for fork()
• fork()
• Clones the child process
• Both parent and child become ready
immediately
State Transitions for exec()
exec()
• Open file, load (or map) contents to memory, reset context
• Process goes to ready state as soon as this happens
• Might block if opening or loading the file takes a while
State Transitions for wait()
wait()
• If child is not running, put process in ready state
• If child is running, put process in blocked state
State Transitions for exit()
exit()
• Terminate process and release resources
• If parent is blocked in wait(), change parent’s state to ready
Example I/O System Calls
• Generic reads/writes to file descriptors
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
• Variants
• Blocking vs non-blocking
• Buffered vs unbuffered
Example I/O System Calls
Functionally equivalent calls
scanf(“%s”, buf)
fscanf(STDIN_FILENO, “%s”, buf)
read(STDIN_FILENO, buf, …)
System calls documented in section 2 and 3 of Man pages
Type “man 2 read” or “man 3 fread” for examples
State Transitions for I/O System Calls
read()
• If error, put process in ready state
• If input is available, put process in ready state
• If no input is available, put process in blocked state
write()
• If error, put process in ready state
• If I/O channel is not available, put process in blocked state, otherwise put
process in ready state