You are on page 1of 41

Lecture 2

OS Concepts
and Structure

17 August, 2010

1
Overview of Basic
Concepts in OS

2
Recall:
Time-Sharing

3
Waiting Area

Task 3 Task 4
Task 2

Task 1

CPU Memory Disk Network

...

4
what do you need to
remember in order to
resume a task?

5
process:
code + data +
context of execution

6
example of
process-related sys calls:
fork( ) waitpid( ) exec( ) exit( )

7
how to prevent one process
from corrupting the memory of
another process?

8
every process has its own
address space

9
a process may occupy
different physical memory
location at different time

10
but the executable code
remains the same.

(e.g., for instruction:


load from address X to register Y
what should X be?)

11
Memory

stack
CPU

data

code

12
Data on disks are organized
into files and directories

13
block special files
character special files
in
/dev

14
pipe

15
example of
file-related sys calls:
open( ) close( ) read( ) write( )
lseek( ) state( )

16
example of
file systems-related sys calls:
mkdir( ) rmdir( )
link( ) unlink( )
mount( ) umount( )

17
User interfaces to OS:
1. shell
2. window systems

18
processes
address space
files and directories
shell
19
Structure of OSes

20
Structure of
Linux Kernel

21
user program
system calls

interrupt dispatcher

hardware

22
user program
system calls

memory process
I/O component
management management

interrupt dispatcher

hardware

23
user program
system calls

virtual file sys

memory process
management management

device drivers

interrupt dispatcher

hardware

24
such design is called
monolithic kernel

25
dynamically loadable
kernel module
keeps the kernel small, extensible
(also in MS Windows, Mac OS X)

26
Alternative to monolithic design:
microkernel

27
An example microkernel architecture

network file systems device drivers

system calls

memory management process management

interrupt dispatcher

hardware
28
keep minimal functions in kernel

example:

29
A brief introduction to
C and programming in
UNIX

30
#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;  
}

31
to compile:

gcc hello.c

gcc -o hello hello.c

gcc -Wall -g -o hello hello.c

gcc -c hello.c; gcc hello.o

32
to debug:
gdb hello

useful gdb commands:


b c l p r s

where set up down watch display finish

33
int  x  =  1;
int  y  =  2;
x  =  y;

34
int  *x;
int  y  =  2;
x  =  &y;
*x  =  3;
y  =  *x;

//  what  is  *y,  &x  ?

35
int  *x;
int  y  =  2;

*x  =  1;

36
int  y  =  2;

f(y);

int  f(int  a)


{
     a  =  2;  
}
37
int  y[3];

*y  =  7;
*(y+1)  =  9

38
char  *name;

name  =  malloc(10);
strcpy(name,  “cs2106”);
 :
 :
free(name);

39
struct  process  {
   int  pid;
   char  *cmd;
   int  status;
}
typedef  struct  process  proc;

40
proc*  create_process()
{
     proc  *p  =  malloc(sizeof(proc));
     //  initialize  fields
     return  p;
}

41

You might also like