0% found this document useful (0 votes)
12 views

Lecture 4

The document provides an overview of key components and concepts related to operating systems: 1) The OS is a program that permits access to hardware and communication between users, software, and hardware. It includes a kernel for core tasks like process management and a shell for the user interface. 2) Interrupts pause the CPU's execution cycle in response to hardware or software events. The OS handles interrupts by running the appropriate interrupt handler. 3) Memory management uses paging and page tables to map virtual memory addresses to physical addresses. Page faults occur when accessing non-resident pages, requiring swapping from disk. 4) Processes are managed through scheduling, queues, and context switching between running,

Uploaded by

heloise maxine
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lecture 4

The document provides an overview of key components and concepts related to operating systems: 1) The OS is a program that permits access to hardware and communication between users, software, and hardware. It includes a kernel for core tasks like process management and a shell for the user interface. 2) Interrupts pause the CPU's execution cycle in response to hardware or software events. The OS handles interrupts by running the appropriate interrupt handler. 3) Memory management uses paging and page tables to map virtual memory addresses to physical addresses. Page faults occur when accessing non-resident pages, requiring swapping from disk. 4) Processes are managed through scheduling, queues, and context switching between running,

Uploaded by

heloise maxine
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

What is an Operating System?

• The OS is a program
– Permit easy access, control hardware, communicate between user
and software, user and hardware, software and hardware, maintain
the computer system (hardware and software)
– Users can access the OS via GUI and command line
• Kernel
– Always resident in memory
– Responsible for primary OS tasks (process management, memory
management, resource management, protection, security)
• Device drivers
– Program interfaces between OS and peripheral devices
• Shell
– User interface, tailorable
• Utility programs
– Add on programs to further manage and fine-tune your system
Interrupts
• The CPU’s fetch-execute cycle runs continuously
unless interrupted
– Interruptions can come from hardware or the running
program
• control+alt+delete
• mouse moved
• printer out of paper
• program has run-time error
– An interrupt interrupts the CPU at the end of fetch-execute
cycle
– Upon interrupt, CPU determines what device (or user or
software) raised interrupt
• select the proper interrupt handler (piece of OS code)
• execute interrupt handler to handle the interrupt
User Interface
• GUI
– Point and click, drag, double click
– Touch screen devices use gesture-based motions (swiping,
tapping, pinching, reverse pinching)
• Command line
– Enter commands from a command line prompt
– Commands executed by an interpreter
• breaks instructions into component parts
• converts instructions to machine code and executes them
• maintains a “session”
• we examine the Bash interpreter in chapter 9
– Commands may look cryptic and be hard to learn but offer
more power and flexibility
• Linux command: find ~ -name ‘core*’ –exec rm {} \;
Process Management and Scheduling
• Process – a running program
– Processes have a status (running, ready, waiting, stopped)
– And data (stored in memory, cache, registers)
• Process management is how the OS handles the tasks of
starting processes, managing running processes,
performing interprocess communication, terminating
processes
• Another aspect is process scheduling – selecting the next
process to run
• Scheduling algorithms include round robin, priority, first
come first serve, shortest job first, longest job first
• Processes wait in queues
– Waiting queue – waiting to be loaded into memory
– Ready queue – in memory, but not currently executing by the CPU
Memory Management
• We may not be able to fit all of our running program(s) in memory
– We use swap space as “backing storage”
– Swap space is placed on the hard disk
• We break our programs into fixed sized units called pages
– The OS moves pages for us between swap space and memory as needed
(on demand)
• This is known as virtual memory
• Program broken into fixed sized pages
– Memory broken into fixed sized frames
• when process begins running, first pages are moved to available frames
• OS maintains page table
– CPU generates a memory address:
• page #, position on page
– Use page table to translate this to physical address
• frame #, position on frame
– If page not in memory, page fault occurs
Virtual Memory: Paging and
Page Tables
Process A page table
Page Frame Valid
0 1 T
1 - F
2 - F
3 3 T
4 0 T

Process B page table


Page Frame Valid
0 - F
1 2 T
2 - F
3 - F
4 - F
5 - F
6 - F

Valid means page in memory


Page Faults and Swapping
• A page fault causes an interrupt
• OS uses a replacement strategy to find frame to
free
– if frame is of a page that has been modified, the page
has to be saved back to swap space
– once a frame is free, new page is loaded from swap
space into memory
– page table updated
• Movement of pages from swap space to memory
(and memory to swap space) is swapping
– swapping slows down the process because disk
Resource Management
• The OS is also • Multitasking processes P0 & P1
responsible for – P0 opens access to file F0
maintaining all other • P0 reads datum X
system resources • P0 adds 10 to X
– disk files, tape drives, – CPU switches to P1
flash drives – P1 opens access to file F0
– network access • P1 reads datum X
– printer access • P1 subtracts 300 from X
• P1 writes new value to F0
• Most resources require
– CPU switches to P0
mutually exclusive
– P0’s value of X is now incorrect
access
– no more than 1 process • This is data corruption
can access a device at a
time, others must wait
Deadlock
• In the above scenario,
P0 is using R0, P1 is
using R1, P0 wants to
access R1 and P1 wants
to access R0
– Deadlock

• The result is that neither P0 nor P1 can continue


• We would have to kill one of the processes to let the
other continue (restart the killed process later)
• OSs will often ignore deadlock and require that the
user discover it and kill one of the processes off
Other OS Tasks
• File management
– Users dictate file system operations through windows
explorer or command line instructions (DOS, Linux)
• creating directories, moving files, copying files, deleting files, etc
– Every file operation is a request
• the OS must ensure that the user has access to the given resource to
perform the operation
• Protection
– Resources need protection from misuse
– Each resource has permissions associated with it (access,
read, write, execute)
– User accounts/authentication are used to establish protection
• Security extends permissions across a network
– A user can then remotely control the computer
Forms of Process Management
• Can the OS run more than one program at any
time?
– not simultaneously but concurrently
• One process at a time
– single tasking
– batch processing
• Concurrent processing
– multiprogramming
– multitasking
– multithreading
Single Tasking and Batch Processing
• Single Tasking • Batch Processing
– User starts the
– For multiple user systems
process
• users submit processes at any time
– Process runs to • off-line system receives requests
completion – OS schedules processes
– If I/O is needed, CPU
– Otherwise, very similar to single
waits
tasking (one program at a time)
– User is not allowed to
– No interactivity because the
run more than 1
process may not be executed
program at a time
until the user is gone
– Most early operating • input supplied with the program
systems were single (e.g., punch cards, magnetic tape)
tasking • output sent to off-line source (tape,
– Most PC operating printer)
systems were single
• Concurrent processing A Context Switch
needs a mechanism • Ready queue – stores those
for the CPU to switch processes available for switching
from one process to – These are processes loaded into
another memory which have either started
– New process needs to execution and been paused or can
be loaded into start execution
memory
• Below, we see a switch between
– Old process’ status
(PC, IR, stack pointer,
process P3 and P7
status flags, etc) saved
to memory
– New process status
(register values)
restored (from
memory)
– During the switch, the
processor is idle
Multiprogramming & Multitasking
• Multiprogramming (or cooperative multitasking) is like batch
processing in that one process is executed at a time except
– When a process requires I/O, it is moved to an I/O queue
– Context switch to next waiting process
– When process finishes with I/O, switch back to it
– More efficient than batch processing or single tasking because the
CPU does not remain idea during time consuming I/O, only delay is
during the context switches
• For multitasking, add a timer and before a process starts, set
the timer to some value (e.g., 10,000)
– After each machine cycle, decrement the timer
– When timer reaches 0, force a context switch to the next process in
the ready queue
– User will not notice the time it takes to cycle through the processes
Multitasking
• More appropriately
called competitive (or
pre-emptive)
multitasking
• Computer appears to
be executing two or
more processes
simultaneously
– it is switching quickly
between processes
• Most OSs do both Competitive multitasking was originally
cooperative and called time sharing in the 1960s
competitive
multitasking today
Threads & Multithreading
• Threads – multiple • Multithreading is
instances of the same multitasking across both
process sharing the processes and threads
same code – Switching between threads is
– But with separate data simpler (less time consuming)
• For instance, you
might have 3 Firefox
windows open, these
are threads of the same
process
• Threads make their
way through the same
code along different
paths
– See figure to the right
Multiprocessing
• Many computers today have multiple processors
– Or multiple cores on one chip (a core is basically a
processor which shares pins and a cache with other
cores on the same chip)
• Multiprocessing is multitasking spread across
multiple processors
• Most OSs are capable of multiprocessing but do
not necessarily share the cores effectively
– For instance, if you have 4 cores, you would not
achieve a 4 times speedup over a computer with a
single core processor
Booting
• Main memory (DRAM, SRAM) is volatile
– Turn off the power, lose the contents
– Turn on the power, memory is empty
• We need the OS loaded and running in memory to
load and run programs
• If you turn your computer on, how do we get the
OS loaded into memory and running when the OS
is needed to load programs into memory to run
them?
– We need a 1-time process – booting
– The boot process (or portions of it) are stored in ROM
(non-volatile memory)
The Boot & Initialization Process
• CPU initializes itself (registers, control signals)
• BIOS performs power on self test
• Disk controllers tested
• BIOS determines where the OS is stored
• Boot loader runs to load OS (if multiple OSs available, user
might be able to select)
• OS kernel loaded and initialized
• OS runs initialization scripts
– Establish runlevel (Linux is a number from 0 to 6, windows is safe
mode, safe mode with network, user mode, etc)
• OS running, computer ready for user
– BIOS is stored in ROM
– Kernel often stored on hard disk (possibly also available on optical
Moving Around
the Linux File
System
Continued
Continued
Continued
DOS
Continued

You might also like