16
Introduction to Computer Science Lecture 3: Operating Systems Tian-Li Yu Taiwan Evolutionary Intelligence Laboratory (TEIL) Department of Electrical Engineering National Taiwan University [email protected] Slides made by Tian-Li Yu, Jie-Wei Wu, and Chu-Yu Hsu Tian-Li Yu Operating Systems 1 / 16

Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Introduction to Computer ScienceLecture 3: Operating Systems

Tian-Li Yu

Taiwan Evolutionary Intelligence Laboratory (TEIL)Department of Electrical Engineering

National Taiwan University

[email protected]

Slides made by Tian-Li Yu, Jie-Wei Wu, and Chu-Yu Hsu

Tian-Li Yu Operating Systems 1 / 16

Page 2: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

History of OS

Batch Processing

Computer operatorsFirst-in, first-out (FIFO)

Job

queue

Job

execution

ResultsJobs

(Programs, data, directions)

User domain

Machine domain

Tian-Li Yu Operating Systems 2 / 16

Page 3: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

History of OS

Interactive Processing

OS with remote terminals

Program

execution

Programs, data,

directions, and results

User domain

Machine domain

Tian-Li Yu Operating Systems 3 / 16

Page 4: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

History of OS

Different Types of OS

Batch

Interactive

Real-time

Response time is critical

Time-sharing and multitasking

Dividing time into intervalsOnly one task is being performed at any given time

Multiprocessor

Load balancingScaling

Tian-Li Yu Operating Systems 4 / 16

Page 5: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Components of OS

Software Classification

Shell Kernel

Utility OperatingSystem

Application System

Software

Tian-Li Yu Operating Systems 5 / 16

Page 6: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Components of OS

Shells

Communication with usersText based.GUI (graphics user interface), such as window manager.

Kernel

User

Shell

Tian-Li Yu Operating Systems 6 / 16

Page 7: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Components of OS

Kernel

File manager

Directory/folder, path

Device drivers

Memory manager

Allocating main memoryPaging, virtual memory

Scheduler

Dispatcher

Can you recognize these shell and kernel components on your PC?

Tian-Li Yu Operating Systems 7 / 16

Page 8: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

GNU/Linux

Linux World

Originally made by Linus Torvalds in 1995.

http://www.linux.org

Freeware & open-source

Many distro (Linux distributions, http://distrowatch.com/)

For beginner: Linux Mint (http://www.linuxmint.com/)Personal favorite: Gentoo (http://www.gentoo.org/)

In fact, Linux means only the kernel.

Better call it GNU/Linux?

Servers, PCs, embedded systems (Android’s kernel is based on Linux).

Tian-Li Yu Operating Systems 8 / 16

Page 9: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Booting

Boot strapping (booting)You may change the booting sequence in BIOS (basic input/output system).

Main Memory

Bootloader

Volatilememory

ROM

Disk strorage

Operatingsystem

Disk strorage

Operatingsystem

Main Memory

Bootloader

Volatilememory

ROM

Operatingsystem

Step 1 Step 2Execute the boot loader program which is already inROM. Operating system is stored in mass storage.

Boot loader program directs the transfer of the operatingsystem into main memory and then transfers control to it.

Tian-Li Yu Operating Systems 9 / 16

Page 10: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Maintaining Processes

Process

Process

The activity of executing a program.

Process state

Program counterGeneral purpose registersAssociated memory cells

Process table

Memory area assigned to the processPriorityReady/waiting

Tian-Li Yu Operating Systems 10 / 16

Page 11: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Maintaining Processes

Process Administration

Scheduler– maintains the process table

Introduces new processes.Removes completed processes.Decides whether a process is ready or waiting.

Dispatcher– really execute the program

Controls the allocation of time slices to the processes in the process table.Process switch (context switch) by calling interrupt.

Tian-Li Yu Operating Systems 11 / 16

Page 12: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Maintaining Processes

Multiprogramming (Time-sharing) Between 2 Processes

Time slice Time slice Time slice Time slice

Process A Process A

Process B Process B

Process

switch

Process

switch

Process

switch

Process

switchB

interruptinterrupt interrupt interrupt interrupt

Tian-Li Yu Operating Systems 12 / 16

Page 13: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Maintaining Processes

Semaphores

A visual signaling apparatus with flags, lights, or mechanically moving arms, as one usedon a railroad. (www.dictionary.com)

Atomic Test-and-Set

Critical region

Mutual exclusion

Operating system concepts

Silberschatz Galvin, 1995

Addison-Wedley

repeat

while Test-and-Set (lock) do no-op;

critical section

lock := false;

remainder section

until false;

Tian-Li Yu Operating Systems 13 / 16

Page 14: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Deadlock

Prerequisites for Deadlock

Deadlock may occur only if all three of the following (necessary but insufficient)conditions are satisfied:

1 Competition for non-shareable resources.2 Resources are requested on a partial basis; that is, having received some resources, a process

will return later to request more.3 Once a resource has been allocated; it cannot be forcibly retrieved.

Tian-Li Yu Operating Systems 14 / 16

Page 15: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Deadlock

Deadlock vs. Starvation

A B C

1 2 3 4

Processes

Resourses

A B C

1 2 3 4

How to grant this request?

Starvation: process cannot get the resources needed for a long time because the resourcesare being allocated to other processes.

Aging: adding an aging factor to the priority of each request.

Tian-Li Yu Operating Systems 15 / 16

Page 16: Introduction to Computer Science Lecture 3: Operating Systemsocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS07L01 .pdf · Introduction to Computer Science Lecture 3: Operating Systems

Security

Security

Insecure passwords & bad habits

Auditing software (record and analyze activities)

Sniffing software

Virus/worms/Trojan horses

Privilege levels & privileged instructions

Tian-Li Yu Operating Systems 16 / 16