You are on page 1of 97

Lecture 1

Introduction
10 August, 2010

1
Instructor
Ooi Wei Tsang
ooiwt@comp.nus.edu.sg

2
Office Hour
Thu 4 - 6pm
AS6 05-14

(was Fri 2-4pm)


3
$ 4 7 . 9 0

Required Textbook
4
$ 4 7 . 0 0

Additional Reference Only


5
Average Weekly Workload
(your milage may vary)

Lecture
2 hr Tutorial
1 hr
Lab
1 hr

Preparation
6 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

Exam
50%

Midterm
20%

Participation
Lab 5%
25%

7
Important Dates
October 2010 November 2010
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6
3 4 5 6 7 8 9 7 8 9 10 11 12 13
10 11 12 13 14 15 16 14 15 16 17 18 19 20
17 18 19 20 21 22 23 21 22 23 24 25 26 27
24 25 26 27 28 29 30 28 29 30
31

midterm final

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

9
Lecture Format
Lecture Break Lecture Break Lecture Dismiss

1200-1400 35 5 35 5 30 10

0 20 40 60 80 100 120

10
slides will be posted
1-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
Light a Fire

Philosophy:
light fire
not fill bucket -
William Yeats

Flickr photo by danielygo Some rights reserved

15
Philosophy:
light fire
not fill bucket -
William Yeats

Flickr
Flickrphoto
photoby
bydanielygo
peasap Some
Some
rights
rights
reserved
reserved
Not 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
CS2106
about?

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 systems
2. abstraction + interface design
3. concurrency
4. resource management
5. 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
CS5223
Distributed Systems

39
CS5231
Systems Security

40
CS5248
Systems Support for
Continuous Media

41
CS6270
Virtual Machines

42
OS
Operating Systems

43
browser calendar ... media player

compilers editors ... shell

operating system

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
consider the simple program:

1. read a number from a file


2. print the number to screen

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
browser calendar ... media player

compilers editors ... shell

file display keyboard mouse printer battery socket

operating system

54
browser calendar .. media player user
mode
compilers editors .. shell

file display keyboard mouse printer battery socket

kernel
operating system (a.k.a 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 Memory

frame stack
pointer

stack
pointer

program
counter
data
program
status word code

59
CPU Memory

CPU
frame stack
pointer
return address
stack saved frame pointer
pointer local variables
function parameters
program
counter
data
program
status word code

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
browser calendar .. media player user
mode
compilers editors .. shell

file display keyboard mouse printer battery socket

kernel
operating system (a.k.a kernel)
mode

67
OS
as a resource manager

68
operating system

processor network
disk space RAM
cycles bandwidth

screen battery
....
estate power

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
and
a 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 datatype
no boolean datatype
no 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
to compile:

gcc hello.c

gcc -o hello hello.c

gcc -g -o hello hello.c

gcc -Wall -g -o hello hello.c

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

You might also like