cs2106 lec2 concept
TRANSCRIPT
-
8/8/2019 CS2106 Lec2 Concept
1/41
Lecture 2
OS Conceptsand Structure
17 August, 2010
1
-
8/8/2019 CS2106 Lec2 Concept
2/41
Overview of BasicConcepts in OS
2
-
8/8/2019 CS2106 Lec2 Concept
3/41
Recall:Time-Sharing
3
-
8/8/2019 CS2106 Lec2 Concept
4/41
CPU Memory Disk
Waiting Area
Task 1
Task 2Task 3
Network
...
Task 4
4
-
8/8/2019 CS2106 Lec2 Concept
5/41
what do you need to
remember in order toresume a task?
5
-
8/8/2019 CS2106 Lec2 Concept
6/41
process:
code + data +context of execution
6
-
8/8/2019 CS2106 Lec2 Concept
7/41
example ofprocess-related sys calls:
fork( ) waitpid( ) exec( ) exit( )
7
-
8/8/2019 CS2106 Lec2 Concept
8/41
how to prevent one process
from corrupting the memory ofanother process?
8
-
8/8/2019 CS2106 Lec2 Concept
9/41
every process has its ownaddress space
9
-
8/8/2019 CS2106 Lec2 Concept
10/41
a process may occupy
different physical memorylocation at different time
10
-
8/8/2019 CS2106 Lec2 Concept
11/41
but the executable code
remains the same.
(e.g., for instruction:
load from address X to register Ywhat should X be?)
11
-
8/8/2019 CS2106 Lec2 Concept
12/41
Memory
stack
data
code
CPU
12
-
8/8/2019 CS2106 Lec2 Concept
13/41
Data on disks are organizedinto files and directories
13
-
8/8/2019 CS2106 Lec2 Concept
14/41
block special files
character special filesin
/dev
14
-
8/8/2019 CS2106 Lec2 Concept
15/41
pipe
15
-
8/8/2019 CS2106 Lec2 Concept
16/41
example offile-related sys calls:open( ) close( ) read( ) write( )
lseek( ) state( )
16
-
8/8/2019 CS2106 Lec2 Concept
17/41
example offile systems-related sys calls:mkdir( ) rmdir( )
link( ) unlink( )
mount( ) umount( )
17
-
8/8/2019 CS2106 Lec2 Concept
18/41
User interfaces to OS:
1. shell2. window systems
18
-
8/8/2019 CS2106 Lec2 Concept
19/41
processes
address spacefiles and directories
shell
19
-
8/8/2019 CS2106 Lec2 Concept
20/41
Structure of OSes
20
-
8/8/2019 CS2106 Lec2 Concept
21/41
Structure ofLinux Kernel
21
-
8/8/2019 CS2106 Lec2 Concept
22/41
interrupt dispatcher
system calls
hardware
user program
22
-
8/8/2019 CS2106 Lec2 Concept
23/41
interrupt dispatcher
system calls
hardware
user program
processmanagement
memorymanagement
I/O component
23
-
8/8/2019 CS2106 Lec2 Concept
24/41
interrupt dispatcher
system calls
hardware
user program
processmanagement
memorymanagement
device drivers
virtual file sys
24
-
8/8/2019 CS2106 Lec2 Concept
25/41
such design is calledmonolithic kernel
25
-
8/8/2019 CS2106 Lec2 Concept
26/41
dynamically loadable
kernel modulekeeps the kernel small, extensible
(also in MS Windows, Mac OS X)
26
-
8/8/2019 CS2106 Lec2 Concept
27/41
Alternative to monolithic design:microkernel
27
-
8/8/2019 CS2106 Lec2 Concept
28/41
interrupt dispatcher
system calls
hardware
process managementmemory management
device driversfile systemsnetwork
An example microkernel architecture
28
-
8/8/2019 CS2106 Lec2 Concept
29/41
keep minimal functions in kernel
example:
29
-
8/8/2019 CS2106 Lec2 Concept
30/41
A brief introduction to
C and programming inUNIX
30
-
8/8/2019 CS2106 Lec2 Concept
31/41
#include
#include
voidsay_hello(inttimes)
{
inti;
for(i=0;i
-
8/8/2019 CS2106 Lec2 Concept
32/41
gcc hello.c
gcc -o hello hello.c
gcc -Wall -g -o hello hello.c
gcc -c hello.c; gcc hello.o
to compile:
32
-
8/8/2019 CS2106 Lec2 Concept
33/41
gdb helloto debug:
useful gdb commands:
b c l p r s
where set up down watch display finish
33
-
8/8/2019 CS2106 Lec2 Concept
34/41
intx=1;inty=2;
x=y;
34
-
8/8/2019 CS2106 Lec2 Concept
35/41
int*x;
inty=2;
x=&y;
*x=3;y=*x;
//whatis*y,&x?
35
-
8/8/2019 CS2106 Lec2 Concept
36/41
int*x;
inty=2;
*x=1;
36
-
8/8/2019 CS2106 Lec2 Concept
37/41
inty=2;
f(y);
intf(inta)
{a=2;
}
37
-
8/8/2019 CS2106 Lec2 Concept
38/41
inty[3];
*y=7;*(y+1)=9
38
-
8/8/2019 CS2106 Lec2 Concept
39/41
char*name;
name=malloc(10);
strcpy(name,cs2106);:
:free(name);
39
-
8/8/2019 CS2106 Lec2 Concept
40/41
structprocess{
intpid;
char*cmd;
intstatus;}
typedefstructprocessproc;
40
-
8/8/2019 CS2106 Lec2 Concept
41/41
proc*create_process(){
proc*p=malloc(sizeof(proc));//initializefieldsreturnp;}