CS2106 Lec1 Intro

Preview:

Citation preview

Lecture 1

Introduction10 August, 2010

1

InstructorOoi Wei Tsang

ooiwt@comp.nus.edu.sg

2

Office HourThu 4 - 6pmAS6 05-14

(was Fri 2-4pm)3

Required Textbook

$47.90

4

Additional Reference Only

$47.00

5

Average Weekly Workload(your milage may vary)

Preparation6 hr

Lab1 hr

Tutorial1 hr

Lecture2 hr

Note that NUS officially lists the workload as 2-1-1-0-4 which is a typo (it does not add up to 10!)

6

Assessment

Midterm20%

Lab25%

Participation5%

Exam50%

7

October 2010Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 910 11 12 13 14 15 1617 18 19 20 21 22 2324 25 26 27 28 29 3031

Important Dates

November 2010Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30

midterm final

8

midterm and final are semi-open book(one 2-sided A4 sheet)

9

Lecture Format

1200-1400

0 20 40 60 80 100 120

1030535535

Lecture Break Lecture Break Lecture Dismiss

10

slides will be posted1-2 days before lecture

but

11

students are expected to take

notes during lecture

12

students are expected to read the assigned readings

13

no “model” answer will be posted

14

Philosophy: light fire

not fill bucket - William Yeats

Flickr photo by danielygo Some rights reserved

Light a Fire

15

Philosophy: light fire

not fill bucket - William Yeats

Flickr photo by danielygo Some rights reservedFlickr photo by peasap Some rights reservedNot Fill a Bucket

16

blog.nus.edu.sg/cs2106

17

your responsibility: check for update frequently

(hint: subscribe via email or RSS)

18

do participate in online discussion

(and use your real name!)

19

screencast will be posted

20

what is

CS2106about?

21

NOT about how to use Mac OS X, MS Windows,

Linux etc.

22

about basic concepts and design principles

in OS

23

why should I learn

OS ?

24

I am not gonna write another OS!25

complex software

26

abstraction + interface design

27

concurrency

28

resource management

29

performance trade-off

30

what to learn from OS course (beside OS):

1. complex systems2. abstraction + interface design3. concurrency4. resource management5. performance trade-off

31

after CS2106

32

CS3221 OS Design and Pragmatics

33

CS3211 Parallel and Concurrent

Programming

34

CS4223 Parallel Computer Architecture

35

CS4275 Programming Real-Time

Systems

36

CS4344 Networked and Mobile

Gaming

37

CS5222 Processor Architecture

38

CS5223Distributed Systems

39

CS5231Systems Security

40

CS5248Systems Support for Continuous Media

41

CS6270Virtual Machines

42

OSOperating Systems

43

operating system

compilers editors shell...

browser calendar media player...

machine language

microarchitecture

physical devices

44

The OS is a layer of software that manages processors, storage and I/O devices and provide simple interfaces to the hardware to user programs.

45

OS is everywhere

46

phone, car, robot, router, media player, game console, ..

47

48

49

1. read a number from a file2. print the number to screen

consider the simple program:

how to code in a world without OS?

50

is the file on a CD, thumbdrive, harddisk..?

location of file on storage?

is another program writing to the file at the same time?

etc..51

what graphics chip is the system using?

what is the display resolution?

is another process writing to the same location?

etc..

52

OS as an extended

machine

53

operating system

compilers editors shell...

browser calendar media player...

file display keyboard mouse printer battery socket

54

operating system (a.k.a kernel)

compilers editors shell..

browser calendar media player..

file display keyboard mouse printer battery socket

user mode

kernel mode

55

interfaces provided by OS are known as system calls

56

Language libraries typically provide a 1-to-1 mapping between library calls and system calls.

e.g.: the function exit( ) calls system call _exit( ).

57

Recall how a library procedure call works..

58

CPU

programcounter

Memory

data

code

stackpointer

programstatus word

stackframepointer

59

CPU

Memory

data

code

stack

function parameterslocal variables

saved frame pointerreturn address

programcounter

stackpointer

programstatus word

framepointer

CPU

60

a system call is similar, except:

1.a special instruction sets the kernel mode bit in PSW before executing the system call

61

2.a special instruction sets the user mode bit in PSW after executing the system call

62

3. CPU executes the OS system call handler.

63

In user mode, certain privileged instructions cannot be executed, certain addresses cannot be accessed etc.

In kernel mode, there is no restriction.

64

Bad things happen in older OSes without dual mode operation.

65

Bad things still happen if buggy code runs in kernel mode.

66

operating system (a.k.a kernel)

compilers editors shell..

browser calendar media player..

file display keyboard mouse printer battery socket

user mode

kernel mode

67

OS as a resource manager

68

operating system

disk space RAM processor cycles

network bandwidth

screen estate

batterypower ....

69

what if the computer runs one task at a time, always completing it before running another task ?

70

a task always have full use of all resources.

not efficient since not all resources are fully utilized at all time (e.g., CPU is idle when I/O is performed).

71

Suppose the computer keeps multiple tasks in the memory. When the running task is idle, switch to another task (multi-programming)

72

now, resources are shared among the tasks.

how does CPU switch from one task to another?

how to prevent one task from corrupting the memory of another task?

73

what if there are multiple users using the system, and there is one CPU intensive task?

74

The computer keeps multiple tasks in the memory and switch between them frequently (regardless of whether the task is idle) (time-sharing)

75

time-multiplexing: CPU, printer

space-multiplexing: memory, disk, screen

76

OS is an extended machine

anda resource manager

77

UNIX and C

78

why UNIX?(Linux, Mac OS X, Sun OS etc.)

79

many OS concepts are cleanly manifested in UNIX

80

source code are available

81

why C?

82

UNIX is written (mostly) in C

83

intermediate-level language (e.g., explicit memory allocation,

bits manipulation)

84

A brief introduction to C and programming in

UNIX

85

C vs Java

(highlights)

86

Java: set of classes

C: set of functions + structures

87

C: no byte datatypeno boolean datatypeno String class

(use char, int, and array of char respectively)

88

Java: all variables are reference except boolean and numeric types

C: all variables are primitive types (holds the value of that exact type)

89

C: no “new” operator

must explicit declare as pointer for reference variables

must explicitly malloc() and free() memory

90

Java: all variables are reference except boolean and numeric types

C: all variables are primitive types (holds the value of that exact type)

91

Java: external classes must be imported

C: external functions and types must be declared

(made easy with #include  statement)

92

int  main(){    return  0;}

93

#include  <stdio.h>

int  main(){    printf(“Hello  World!\n”);    return  0;  }

94

gcc hello.c

gcc -o hello hello.c

gcc -g -o hello hello.c

gcc -Wall -g -o hello hello.c

to compile:

95

#include  <stdio.h>#include  <stdlib.h>

void  say_hello(int  times){    int  i;    for  (i  =  0;  i  <  times;  i++)        printf(“Hello  World\n”);}

int  main(int  argc,  char  *argv[]){    say_hello(atoi(argv[1]));    return  0;  }

96

*97