Software Layers 2 Introduction to unix 2


How the OS allows simultaneously running of programs



Download 0.58 Mb.
Page3/26
Date28.01.2017
Size0.58 Mb.
#10070
1   2   3   4   5   6   7   8   9   ...   26

How the OS allows simultaneously running of programs


Computers usually have only one CPU (note: more CPUs  more problems...)

note: for programs to run simultaneously  must use CPU at the same time.

  • the OS schedules small amounts of time (milliseconds) for programs to use the CPU

  • the Fetch-Decode-Execute Cycle may proceed during these small amounts of time on a given program  constant switching of programs gives the impression of all programs running together


eg: 3 programs are running: pine, pico, tcsh  the OS may schedule these programs like this:

Time (ms)

Running Program

Waiting Program(s)

0.000

tcsh

pine, pico

0.001

pine

pico, tcsh

0.002

pico

tcsh, pine

Round-Robin Scheduling  This kind of scheduling continuously cycles over the waiting programs


Some different way of scheduling programs: first-come first-served, shortest job first, priority scheduling, round-robin, etc.



How the OS controls main memory


  • programs execute in a block of main memory (the blocks are separate from each other)

  • one program for one block of main memory

  • when a program ends, the OS reclaims the memory block

  • note: If there is not enough memory  programs wait until the OS can provide memory and the OS re-organises the blocks so that waiting is reduced

The OS uses the MMU (memory management unit) of a CPU:



  • the MMU allows communication between CPU & memory

  • it makes sure memory requests are valid

  • typically, programs have "logical" memory addresses from which "physical" memory addresses are computed by the MMU (& vice versa)

  • this allows the OS to relocate programs in memory if necessary!


eg: Two programs need to be allocated memory: xgdb needs 3MB pine needs 0.5MB


Memory currently contains:

Address (MB)

Contents

0 to 1

OS

1 to 2

Graphics Buffer

2 to 4

Device Drivers

4 to 8

*free*

The OS allocates xgdb & then pine

(biggest program first):



Address (MB)

Contents

0 to 1

OS

1 to 2

Graphics Buffer

2 to 4

Device Drivers

4 to 7

xgdb

7 to 7.5

pine

7.5 to 8

*free*




Then xgdb finishes, & the OS reclaims the 3MB:

Address (MB)

Contents

0 to 1

OS

1 to 2

Graphics Buffer

2 to 4

Device Drivers

4 to 7

*free*

7 to 7.5

pine

7.5 to 8

*free*


note: If a new program requests 2.5MB

  • pine moved to 4-4.5

  • new program occupies 4.5-7




How does the OS handle file requests?

Files are stored in secondary storage (eg: disk drives)

Files change over time and occupy various parts of a disk:
A file look-up table records where the file is stored.

Potential problems arise when:



  • 2 programs try to change the same file at the same time

  • a program does not have correct access privileges


Download 0.58 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   ...   26




The database is protected by copyright ©ininet.org 2024
send message

    Main page