Basics of Operating Systems: What Is An Operating System?
Basics of Operating Systems: What Is An Operating System?
Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
! Many definitions - better to describe what OS's do ! Provide an abstraction over hardware ! Standard interfaces to a variety of hardware ! Provide a user interface (not required, but most do) ! Provide an Application Programming Interface ! Manage resource sharing ! CPU, disk drives, network, sound, video, keyboard, mouse, ... ! Key objectives depend on OS (e.g., Linux vs. Windows vs. PalmOS)
OS Basics, cont.
OS Basics, cont.
OS Basics, cont.
OS Basics, cont.
Concurrency: CPU
! Process (a virtual machine): a set of instructions + a state ! The virtual machine executes each instruction against its state ! A state includes all the data used by the execution stream ! States implemented by a variety of hardware registers, stack, RAM, hard drive ! Objective: Fair sharing, protection - processes cannot directly change each others states (enforced by OS) ! Communication: done through shared memory or other resources 5
Processes
! Context switching ! OS runs one process, then another, then another ! In between, the OS saves the state of the current process, then loads the state of the next process ! When do you switch contexts? ! Typically, OS designer decides policy: timeslicing, pre-emptive, priority-based, ... ! Objectives: response time, efficient resource utilization
6
OS Basics, cont.
OS Basics, cont.
Processes, cont.
! Context switching is typically expensive! ! Save process state (register, I/O state, stack, memory) ! Flush cache if necessary (ouch) ! Load new process state ! Run new process ! How can we mitigate the expense of context switching? ! Make tradeoffs - threads
7
Threads
! Like a process, except that some state is shared ! Threads have their own registers and stack frames ! Threads share memory ! Tradeoffs: Ease of programming + better performance vs. programming complexity + less protection ! Switching to another thread: save registers, find the right stack frame, load registers, run thread ! Typically used to service asynchronous events
OS Basics, cont.
OS Basics, cont.
10
OS Basics, cont.
OS Basics, cont.
OS Basics, cont.
OS Basics, cont.
OS Basics, cont.
OS Basics, cont.