Major Services Provided by an Operating System - PowerPoint PPT Presentation

1 / 65
About This Presentation
Title:

Major Services Provided by an Operating System

Description:

A process can create another process: A parent process creates a child process ... The exec family of system calls is used to replace the current process's program. ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 66
Provided by: chrisw50
Category:

less

Transcript and Presenter's Notes

Title: Major Services Provided by an Operating System


1
Major Services Provided by an Operating System
  • process management and scheduling
  • main-memory management
  • secondary-memory management
  • input/output system management, including
    interrupt handling
  • file management
  • protection and security
  • networking
  • command interpretation

2
CPU Interrupt
  • Transfers execution to service routine associated
    with the interrupt
  • Interrupt vector array of addresses to service
    routines (stored at beginning of memory)

3
Operating System Design Factors
  • Ease of Use
  • Resource Utilization
  • Performance
  • Other goals
  • Easy to extend
  • Portable
  • Easy to install/uninstall

4
Dual-Mode Operation
  • In dual-mode operation, there are two separate
    modes monitor mode (also called 'system mode'
    and 'kernel mode') and user mode.
  • In monitor mode, the CPU can use all instructions
    and access all areas of memory.
  • In user mode, the CPU is restricted to
    unprivileged instructions and a specified area of
    memory.

5
C Library to System Call
include ltstdio.hgt int main() printf(Hello
World) return 0
User mode
standard C library
Kernel mode
write() system call
6
Processes
  • Program code (aka text section)
  • Current activity
  • Program counter
  • CPU register contents
  • Process stack
  • Function parameters, return addresses, local
    variables
  • Data section
  • Global Variables
  • Heap - Memory dynamically allocated to the
    process during the process run time

7
PCB in Linux
pid_t pid / process identifier / long state
/ state of the process / unsigned int
time_slice / scheduling info / struct
files_struct files / list of open files
/ struct mm_struct mm / address space /
8
new
terminated
interrupt
exit
admitted
ready
running
scheduler
I/O or event done
I/O or wait
waiting
9
process P0 OS
process P1
executing
interrupt/system call
save state into PCB0
reload state from PCB1
executing
interrupt/system call
save state into PCB1
reload state from PCB0
executing
10
Process Creation
  • A process can create another process
  • A parent process creates a child process
  • When a child process is created, the parent
    process may either
  • Continue to execute concurrently with the child
  • Wait until some or all of its children have
    terminated. Child processes whose parent
    terminates first are called orphan processes.

11
UNIX Process Creation
process running
fork()
parent
child
wait()
exit()
resumes
12
include ltsys/types.hgt // for pid_t include
ltstdio.hgt include ltunistd.hgt int
main() pid_t returned_pid fork() if
(returned_pid 0) / do child stuff
/ exit(0) else if (returned_pid gt
0) wait(NULL) / wait for child
/ printf(Child terminated!) exit(0) e
xit(1)
13
exec()
  • The exec family of system calls is used to
    replace the current process's program.
  • An exec system call loads a binary file into the
    text section of the current process.
  • Now the process is running a different program.
  • An exec system call is often called (by the
    child) after the fork() system call.

14
process running
fork()
child
parent
exec()
wait()
resumes
exit()
15
include ltsys/types.hgt // for pid_t include
ltstdio.hgt include ltunistd.hgt int
main() pid_t returned_pid fork() if
(returned_pid 0) execlp(ls, ls, (char
) NULL) exit(0) else if (returned_pid gt
0) wait(NULL) / wait for child
/ printf(Child terminated!) exit(0) e
xit(1)
16
Interprocess Communication
  • Shared Memory
  • A region of memory is allocated and shared by
    cooperating processes.
  • Message Passing
  • Messages are exchanged between cooperating
    processes

17
Process Scheduling
  • Objective
  • Have a process running on the CPU at all times.
  • The Process Scheduler is in charge of selecting
    the next process to start executing on the CPU.
  • Preemptive scheduling remove a process from the
    CPU before it is finished.

18
Process Scheduling
  • The scheduler maintains various queues of
    processes
  • JOB QUEUE As a process enters the system, it is
    placed in a "job queue
  • READY QUEUE All processes residing in main
    memory that are ready and waiting are kept in a
    list called the ready queue.

19
Scheduling Criteria
  • CPU Utilization
  • 0 to 100
  • Throughput
  • Number of processes completed per time unit.
  • Turnaround Time
  • Interval of time when a process enters the system
    until it exits.
  • Waiting Time
  • sum of time spent in the waiting queue (for a
    particular process).
  • Response Time
  • time from the submission of a request (ex. I/O
    request) until the first response to the request
    is produced.

20
Scheduling Algorithms
  • First-Come, First-Served (FCFS)
  • The process that requests CPU first gets the CPU
    first
  • Shortest-Job-First Scheduling (SJF)
  • Give the CPU to the process that has the smallest
    next CPU burst
  • Approximate with exponential average
  • pn1 a tn (1 - a)pn

21
Scheduling Algorithms
  • Priority Scheduling
  • Each process is assigned a priority, and the CPU
    is allocated to the process with the highest
    priority.
  • Round-Robin Scheduling
  • Define a time quantum to be a small unit of time
    (10-100 milliseconds)
  • The scheduler goes around the ready queue,
    allocating the CPU to each process for some time
    less than or equal to the time quantum

22
Memory Hierarchy
http//www2.cs.uregina.ca/hamilton/courses/330/no
tes/memory/MemoryHierarchy.html
23
Address Binding
  • Compile time absolute addresses are bound at
    compile time must know where the process will
    reside in memory.
  • Load time the absolute addresses are determined
    from the relocatable addresses when the program
    is loaded.
  • Execution time the absolute addresses are
    generated as the program runs.

24
Swapping
  • A process can be swapped temporarily out of
    memory to backing store (disk), and then
    subsequently brought back into memory for
    continued execution
  • When swapping is used, the ready queue contains
    all ready processes whose images are on the
    backing store or in memory

25
Memory Allocation
  • External Fragmentation
  • As processes are loaded and removed from memory,
    the free space is broken into pieces or
    fragments.
  • External fragmentation exists when the total free
    memory is large enough to fullfill a request, but
    the free space is not contiguous

26
Internal fragmentation
  • To combat external fragmentation, some systems
    will allocated memory is fixed-sized blocks.
  • In this scheme, the memory allocated may be
    larger than the request
  • The wasted memory internal fragmentation

27
Simple Paging
  • Partition physical memory into fixed-sized blocks
    called frames.
  • Partition logical memory into same-sized blocks
    called pages.
  • When a process is to be executed, its pages are
    loaded into available memory frames in the
    backing store.

28
Simple Paging
  • A logical address is divided into two parts
  • A page number (p)
  • A page offset (d)
  • p is used to index the page table f table(p)
  • The address f,d is used to index physical memory
  • How to calculate p and d
  • Logical address space is 2m
  • Page size is 2n
  • Use the (m-n) higher-order bits of a logical
    address for p, and the rest of the bits for d

29
Simple Paging
Logical Memory
Physical Memory
Page Table
Logical Address Space 24
Page size 22
gt Use first (4-2) 2 high-order bits from
logical address for p, the page table
index gt Use remaining 2 bits for d, the page
offset
30
Simple Paging
Logical Memory
Physical Memory
Page Table
Ex. Logical address 11 1110 10112
p 102 210 d 112
gt page table 110 012
gt physical address 01112 710
31
Simple Segmentation
  • An address is specified by a segment name/number
    and a segment offset
  • Typically a compiler automatically constructs
    segments from the source code
  • Ex. A C compiler may create segments for
  • The code
  • Global variables
  • The heap
  • The stacks

32
Demand Paging and Virtual Memory
  • Memory management technique that allows execution
    of process that are not completely in memory.
  • Abstracts main memory into an extremely large
    array of storage

33
Demand Paging
  • Pages are loaded when they are demanded during
    the execution of a program
  • OS program that swaps in demand-paged virtual
    memory system is called pager

34
Demand Paging
  • What happens when a process tries to access a
    page that was not brought into memory by the
    pager?
  • Paging hardware transfers control to OS
  • Check internal table in PCB to ensure the memory
    access is valid
  • Find a free frame in main memory
  • Schedule a disk operation to read the page into
    the allocated frame
  • When page is copied into frame, update PCB and
    page table
  • Restart the instruction that was interrupted by
    the trap

35
Effective Memory Access Time
  • Define the following
  • Let ma be the memory-access time
  • Let p be the probability of a page fault
  • Let f be the page-fault time
  • effective access (1 - p) X ma p X f

36
Copy-on-Write
  • When a child process is created, instead of
    copying the pages of the parent, the child and
    parent can simply share the pages of the parent.
  • When the either the parent or the child attempts
    to write to a page, the page is first copied, and
    that copied page is used by the process instead
  • Used in Windows XP, Linux, and Solaris

37
Page Replacement
  • Suppose a page needs to be placed in memory.
  • A frame is requested, but no free-frames are
    available
  • In this situation, we need to remove a page from
    memory to free-up a frame

38
Basic Page Replacement
  • Find a frame whose page is not currently in use.
  • Write the contents (page) of the frame to swap.
  • Update page table and frame tables.

39
Page Replacement Algorithms
  • First-In First-Out (FIFO)
  • Each page has a time stamp when it was brought
    into memory.
  • When a page must be replaced, the oldest page is
    chosen.
  • Least-Recently-Used (LRU)
  • Replace the page that has not been used for the
    longest period of time.
  • Each page has an associated time of that page's
    last use.

40
Page Replacement Algorithms
  • LRU-Approximation
  • Many hardware systems do not have support for the
    LRU page replacement algorithm
  • Second-Chance Algorithm
  • Use FIFO selection, but if the selected page has
    reference bit equal to 1, then the reference bit
    is set to 0, and the arrival time is set to the
    current time. Then consider next FIFO page.

41
Thrashing
  • Thrashing occurs when the processes are not
    allocated enough frames, and there is a large
    number of page-faults
  • CPU utilization drops as the system spends most
    of its time performing paging operations
  • A process is thrashing if it is spending more
    time paging then executing

42
Process Synchronization
  • A semaphore is an integer variable S that is
    accessed via only two atomic operations
  • wait(S)
  • signal(S)

43
Semaphores
  • wait(S)
  • while (S lt 0)
  • S--
  • signal(S)
  • S

44
Synchronization Terms
  • Deadlock
  • Monitors
  • Busy wait
  • Critical Section

45
File Systems
  • Logical View
  • Physical View
  • Symbolic Link
  • Hard Link
  • Protection (in Unix)

46
Disk Allocation Algorithms
  • Contiguous Allocation
  • Each file occupies a set of contiguous blocks
  • Linked Allocation
  • Each file is a linked-list of blocks
  • Indexed Allocation
  • Index block contains pointers to the blocks

47
The UNIX inode
mode
data
owners
timestamps
data
direct blocks
. . .
data
. . .
data
data
data
single indirect
double indirect
. . .
triple indirect
. . .
data
data
48
Free-space Managment
  • Bit-Vector
  • Each block is represented as 1 bit
  • Linked-List
  • Grouping
  • First free block store pointers to other free
    blocks
  • Counting
  • Block addresses and count of following free
    blocks

49
Disk Scheduling
  • When a process requests I/O to or from the disk,
    it specifies
  • Read or write
  • Disk address
  • Memory address for the transfer
  • Number of sectors
  • Disk I/O requests will be placed in a queue if
    they cannot be serviced immediately.
  • How do we choose which request to service next?
  • Disk Scheduling

50
First-Come, First-Served (FCFS)
Requests (cylinders) 98, 183, 37, 122, 14, 124,
65, 67
(assume head initially is at 53)
0
14
37
53
65
67
98
122
124
183
199
640 head movements
51
Shortest-Seek-Time-First (SSTF)
  • Select the request with the minimum seek time
    from the current head position.
  • Intuition since we must service this request
    eventually, we might as well service it while the
    disk head is close.

52
First-Come, First-Served (FCFS)
Requests (cylinders) 98, 183, 37, 122, 14, 124,
65, 67
(assume head initially is at 53)
0
14
37
53
65
67
98
122
124
183
199
236 head movements
53
SSTF Problems
  • Constantly switching directions slows things
    down.
  • Starvation
  • Suppose requests continually arrive for cylinders
    near the current position.
  • If a request is in the queue that is far away
    from the current head position, it may remain
    pending indefinitely.

54
SCAN Scheduling
  • Disk arm moves one direction, servicing requests
    as it moves, until it reaches the end of the
    disk.
  • Then it reverses direction, and continues to scan
    and service requests.

55
SCAN
Requests (cylinders) 98, 183, 37, 122, 14, 124,
65, 67
(assume head initially is at 53)
0
14
37
53
65
67
98
122
124
183
199
236 head movements
56
C-SCAN
  • Variant of SCAN where the disk head moves from
    one end of the disk to the other, then resets to
    its original position, and repeats.
  • Does not service requests as it resets

57
C-SCAN
Requests (cylinders) 98, 183, 37, 122, 14, 124,
65, 67
(assume head initially is at 53)
0
14
37
53
65
67
98
122
124
183
199
383 head movements (200 for reset)
58
LOOK and C-LOOK
  • LOOK is a variant of SCAN where the disk head
    only goes as far as the furthest request.
  • C-LOOK is a variant of C-SCAN where the disk head
    only moves as far as the furthest request.

59
C-LOOK
Requests (cylinders) 98, 183, 37, 122, 14, 124,
65, 67
(assume head initially is at 53)
0
14
37
53
65
67
98
122
124
183
199
322 head movements
60
Summary
  • SSTF or LOOK are often used.
  • SCAN and C-SCAN are better suited for systems
    will heavy disk loads since starvation is
    eliminated.
  • If disk requests are very sparse, all algorithms
    are about the same.
  • Disk manufacturers will often implement a disk
    scheduling algorithm in the controller.

61
RAID
  • Redundant Array of Independent Disks
  • Read/write speed
  • Reliability of data storage
  • Redundancy
  • Mirroring every write is carried out on each
    disk
  • If one disk fails, the data is read from another
    disk

62
Data Striping in RAID
  • Data Striping split data among multiple disks.
  • Bit-Level split the bits in a byte
  • Block-Level split blocks of a file
  • Increases throughput by load balancing
  • Reduces response time of large accesses

63
RAID Levels
  • RAID schemes have been developed that combine
    disk striping with parity bits.
  • Provides redundancy and speed increase
  • The various schemes are implemented as different
    RAID levels.

64
Distributed Systems
  • Why?
  • Resource Sharing
  • Computation Speedup
  • Reliability
  • Communication
  • Cache-Update Policy
  • Cache Consistency

65
Election Algorithms
  • Bully Algorithm
  • When coordinator failure detected, try to elect
    self.
  • If receive election message from lower priority
    process, respond and start own election.
  • Ring Algorithm
  • Send elect message upon coordinator failure.
  • Keep active list of elect messages
Write a Comment
User Comments (0)
About PowerShow.com