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
Control registers
Control registers: Registers in the CPU that are used to store control
information on state of program execution, for example, the program counter and
stack pointer.
Data registers
Registers in the CPU that are used to store the intermediate
data used when executing instructions.
System call
executed in kernel mode and thus requires a context switch.
Provide an interface for the user to interact with the OS and request functionality.
Each system call has a call number, which is used by the system call dispatcher
to lookup the code associated with the invoked system call.
Blocked queue
a process is placed on the blocked queue, maintained by the
OS, if it is waiting for some condition to be true before it is able to proceed in its
execution; one example is a process waiting for a response from an I/O device
that is not ready
TRAP call
a series of assembly instructions leading to he privilege bit being
flipped in the CPU to switch it from operating in user mode to kernel mode
CPU cache
CPU cache: stores copies the data that is frequently accessed by this processor
Disk operation
an operation requiring a response from the external disk
memory
Interrupt
Interrupt: a notification to the OS for an event that requires servicing; the
interrupt may originate from a hardware device or software condition
Interrupt identifier
Interrupt identifier: used by the OS to map the interrupt notification to the
appropriate handler for the event
Disk device driver
Disk device driver: device drivers are used as an interface between the
hardware and software to allow the operating system to ignore the specific
details of the hardware component being used
Interrupt handler
Interrupt handler: A function that is run whenever a particular type of interrupt is
invoked and received by a process.
Segmentation faults (C programming)
Segmentation faults (C programming): a failure that occurs when the program
attempts to access a restricted portion or memory, or read/write illegally (e.g.
write to a read-only location of memory). This is a means of notifying the OS of
the illegal action, and results in memory protection for the machine.
Pointer (C programming)
Pointer (C programming): store the addresses or memory locations of variables
Dereferencing (C programming)
Dereferencing (C programming): use the address value from the pointer to
access the data in the memory location
Hardware Interrupts
Hardware Interrupts: interrupts that are generated at the hardware level,
typically in response to an external event such as a clock tick or completion of a
disk request.
Clock pulse
Clock pulse: All motherboards usually come with its own clock. Every clock tick
generates a pulse which is delivered to the operating system in order to advance
current time and invoke the scheduler.
Illegal instruction
Illegal instruction: A hardware instruction that is disallowed, for example, an
instruction that cannot be run due to lack of privileges or an instruction that
touches memory location that is not available to the current process.
Scheduler
Scheduler: a piece of software that resides in the scheduler that decides which
process to run next.
Interrupt Service Routine
Interrupt Service Routine: whenever a hardware interrupt arrives, it is delivered
to the operating system where there is a piece of software called the interrupt
service routine that decides how to handle the interrupt. This is analogous to the
signal handler.
Hardware interrupt ID
Hardware interrupt ID: a unique identifier assigned to each hardware interrupt.
The interrupt service handler uses this to decide how to handle the specific
interrupt.
Custom handlers
Custom handlers: signal handlers that provided in user space and is
customized by the application for handling the particular signal.
Default handlers
Default handlers: signal handlers that are default in the operating system.
Signal relaying
sending one signal from one process to another through the
kernel.
Preemptible signal handlers
when a signal handler is running and a new
signal arrives, rather than complete running the signal, if the handler is
“preemptible”, it means we can stop the current handler and deal with the signal
first.
Signal blocking
a signal being buffered and delayed at the operating system
and not delivered to the process until it is explicitly unblocked.
Multiprogramming
Run multiple applications at the same time, protecting
them from one another and sharing the CPU between them
Hierarchical file system
Store data on disk persistently organized in a tree
structure
Plug-and-play devices
Software that allows external devices (e.g. printers
and scanners) to interact with applications
Virtual memory
Graphical User Interface
ENIAC
The Electronic Numerical Integrator and Computer (ENIAC) was the
first general-purpose electronic computer. ENIAC was developed at the
University of Pennsylvania
Punch cards
Pieces of stiff papers with holes in them, where the presence
and absence of holes is used to encode digital information about data or
programs
Resident Monitor
A piece of software that is a precursor to modern
operating systems. This software runs in memory and in the punch card era,
and was used to process one punch card at a time
Operating System (OS)
A piece of software that is layered between
applications and hardware, allowing multiple applications to share the same
physical machine resources and gain access to external devices
Time-Sharing
The ability to share one physical compute resource among
multiple applications.
Multics
A time-sharing operating system developed by MIT, General Electric,
and Bell Labs for mainframes in the 60s
Compatible Time Sharing System (CTSS)
An operating system developed
by MIT that shares similar time-sharing features as Multics
Linux
An open-source operating system commonly used on both home and
server machines. Linux is closely modelled after its predecessor Unix
Unix
A well-known operating system developed by Bell Labs that has many
of the features used in modern operating systems, such as time-sharing, a
Shell, and a hierarchical file system
MS-DOS
An early operating system developed for end-user computers by
Microsoft. MS-DOS introduced the command prompt interfaces seen in many
subsequent versions of Windows
Berkeley Standard Distribution (BSD)
A Unix distribution developed by the
University of California, Berkeley. It is most well-known for its pioneering
implementation of the TCP/IP protocol used over the internet today
Ubuntu
A popular distribution of Linux that is considered easy to install and
easily usable by the non-expert
Virtualization
A method for dividing up physical compute resources into
logical separate units usable by different users. The most common example is
running multiple operating systems that share one physical machine