Design philosophy of operating systems (III)
Recap: impact of UNIX
Clean abstraction everything as a file
Copyright By Assignmentchef assignmentchef
File system will discuss in detail after midterm
Portable OS
Writteninhigh-levelCprogramminglanguage
TheunshakablepositionofCprogramminglanguage
We are still using it!
Recap: Each process has a separate virtual memory space
static data
heap Virtual memory
static data
heap Virtual memory
static data
heap Virtual memory
static data
heap Virtual memory
They are isolated from one another. Each of them is not supposed to know what happens to another one
Virtually, every process seems to have a processor, but only a few of them are physically executing.
Recap: impact of UNIX
Clean abstraction everything as a file
File system will discuss in detail after midterm
Portable OS
Writteninhigh-levelCprogramminglanguage
TheunshakablepositionofCprogramminglanguage
We are still using it!
Recap: Review the first demo
UNIX Recap: Protection mechanisms
Protectionisassociatedwitheachfiledescribedinthemetadata
Each file contains three (only two in the original paper) types of
Each type of users can have read, write, execute permissions setuid to promote right amplifications
The basic process API of UNIX
What happens if we execute the following code?
int main() {
the parents PID is 2; childs PID is 7.
if ((pid = fork()) == 0) {
} printf (My pid is %d
, getpid());
printf (Child pid is %d
, pid);
What will happen?
# of times my pid is printed
my pid values printed
# of times child pid is printed
child pid values printed
UNIXs interface of managing processes
What happens if we add an exit?
int main() {
if ((pid = fork()) == 0) {
printf (My pid is %d
, getpid());
} exit(0);
printf (Child pid is %d
, pid);
return 0; }
the parents PID is 2; childs PID is 7.
Ifweaddanexit
# of times my pid is printed
my pid values printed
# of times child pid is printed
child pid values printed
fork() and exit()
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
fork() and exit()
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
fork() and exit()
Output: Mypidis7
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
fork() and exit()
Output: Mypidis7
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
fork() and exit()
Output: Mypidis7
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
fork() and exit()
Output: Mypidis7 Child pid is 7
if ((pid = fork()) == 0) {
printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
static data
heap stack
Virtual memory
What happens if we add an exit?
int main() {
if ((pid = fork()) == 0) {
printf (My pid is %d
, getpid());
} exit(0);
printf (Child pid is %d
, pid);
return 0; }
the parents PID is 2; childs PID is 7.
# of times my pid is printed
Ifweaddanexit
my pid values printed
# of times child pid is printed
child pid values printed
Poll close in
Consider the following code
printf(moo
);
printf(oink
);
printf(baa
);
How many animal noises will be printed? A. 3
B. 6 C. 8 D. 14 E. 24
More forks
Poll close in
Consider the following code
printf(moo
);
printf(oink
);
printf(baa
);
How many animal noises will be printed? A. 3
B. 6 C. 8 D. 14 E. 24
More forks
Consider the following code
fork(); 2x printf(moo
);
printf(oink
);
printf(baa
);
How many animal noises will be printed? A. 3
More forks
Starting a new program with execvp() int execvp(char *prog, char *argv[])
What execvp does:
Stopsthecurrentprocess
Overwritesprocessaddressspaceforthenewprogram Initializeshardwarecontextandargsforthenewprogram Insertstheprocessintothereadyqueue
execvp does not create a new process 21
fork does not start a new program, just duplicates the current
Why separate fork() and exec()
Windows only has exec
Flexibility
Allows redirection & pipe
Theshellforksanewprocesswheneveruserinvokeaprogram
Afterfork,theshellcansetupanyappropriateenvironment
variable to before exec
The shell can easily redirect the output in shell: a.out > file
if ((pid = fork()) == 0) { execvp(a.out,NULL); printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
Virtual memory static data
heap stack
if ((pid = fork()) == 0) { execvp(a.out,NULL); printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
Virtual memory static data
heap stack
if ((pid = fork()) == 0) { execvp(a.out,NULL); printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
Virtual memory static data
heap stack
Output: Child pid is 7
if ((pid = fork()) == 0) { execvp(a.out,NULL); printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
Virtual memory static data
heap stack
if ((pid = fork()) == 0) { execvp(a.out,NULL); printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
Virtual memory static data
heap stack
Output: Child pid is 7
New program!
if ((pid = fork()) == 0) { execvp(a.out,NULL); printf(My pid is %d
, getpid());
printf(Child pid is %d
, pid);
Virtual memory static data
heap stack
int main() {
printf(New program!);
}return 0;
Virtual memory static data
heap stack
Poll close in
Whats in the kernel?
How many of the following UNIX features/functions are implemented
in the kernel?
! I/Odevicedrivers
Filesystem
$ Virtualmemorymanagement A. 0
B. 1 C. 2 D. 3 E. 4
Poll close in
Whats in the kernel?
How many of the following UNIX features/functions are implemented
in the kernel?
! I/Odevicedrivers
Filesystem
$ Virtualmemorymanagement A. 0
B. 1 C. 2 D. 3 E. 4
Lets write our own shells
How to implement redirection in shell
Say, we want to do ./a > b.txt
The forked code opens b.txt
The forked code dup the file descriptor
The forked code assigns b.txt to stdin/stdout The forked code closes b.txt
exec(./a, NULL)
How to implement redirection in shell
Say, we want to do ./a > b.txt
The forked code opens b.txt
Homework for you:
Think about the case when
your fork is equivalent to fork+exec()
The forked code dup the file descriptor to stdin/stdout The forked code closes b.txt
exec(./a, NULL)
int pid, fd;
char cmd[2048], prompt = myshell$ while(gets(cmd) != NULL) {
if ((pid = fork()) == 0) {
fd = open(b.txt, O_RDWR | O_CREAT, S_IRUSR |
S_IWUSR); dup2(fd, stdout); close(fd);
}execv(./a,NULL);
} printf(%s ,pro
static data
The shell can respond to next in
heap stack
int pid, fd;
char cmd[2048], prompt = myshell$ while(gets(cmd) != NULL) {
if ((pid = fork()) == 0) {
fd = open(b.txt, O_RDWR | O_CREAT, S_IRUSR |
S_IWUSR); dup2(fd, stdout); close(fd);
}execv(./a,NULL);
} printf(%s ,pro
static data
heap stack
pid_t wait(int *stat)
pid_t waitpid(pid_t pid, int *stat, int
wait / waitpid suspends process until a child process ends wait resumes when any child ends
waitpid resumes with child with pid ends
exit status info 1 is stored in *stat
Returnspidofchildthatended,or-1onerror
Unix requires a corresponding wait for every fork
Whats in the kernel?
How many of the following UNIX features/functions are implemented
in the kernel?
! I/Odevicedrivers
Filesystem
$ Virtualmemorymanagement A. 0
user-level kernel
privilege boundary
A user program provides an interactive UI
Interprets user command into OS functions
Basic semantics:
command argument_1 argument_2
Advanced semantics
Redirection >
Multitasking
Clean abstraction The impact of UNIX
File system will discuss in detail after midterm
Portable OS
Writteninhigh-levelCprogramminglanguage
TheunshakablepositionofCprogramminglanguage
We are still using it!
Mach: A New Kernel Foundation For UNIX
Development
, , , , , ,
Computer Science Department, University
Poll close in
Why is Mach proposed?
How many of the following statements is/are true regarding the motivations
of developing Mach in 1986?
! ModernUNIXsystemsdonotprovideconsistentinterfacesforsystemfacilities
SystemlevelservicescanonlybeprovidedthroughfullyintegrationoftheUNIX kernel
# Theprocessabstractioncannotusemultiprocessorsefficiently $ Networkcommunicationisnotprotected
Poll close in
Why is Mach proposed?
How many of the following statements is/are true regarding the motivations
of developing Mach in 1986?
! ModernUNIXsystemsdonotprovideconsistentinterfacesforsystemfacilities
SystemlevelservicescanonlybeprovidedthroughfullyintegrationoftheUNIX kernel
# Theprocessabstractioncannotusemultiprocessorsefficiently $ Networkcommunicationisnotprotected
The cost of creating processes
Measure process creation overhead using lmbench http://
www.bitmover.com/lmbench/
The cost of creating processes
On a 3.2GHz intel Core i5-6500 Processor Processfork+exit:53.5437microseconds
Morethan16Kcycles
Measure process creation overhead using lmbench http://
www.bitmover.com/lmbench/
Why is Mach proposed?
How many of the following statements is/are true regarding the motivations
of developing Mach in 1986?
! ModernUNIXsystemsdonotprovideconsistentinterfacesforsystemfacilities
SystemlevelservicescanonlybeprovidedthroughfullyintegrationoftheUNIX kernel
# Theprocessabstractioncannotusemultiprocessorsefficiently $ Networkcommunicationisnotprotected
The hardware is changing
Multiprocessors
Why Mach?
Networkedcomputing
The software
ThedemandofextendinganOSeasily
Repetitivebutconfusingmechanismsforsimilarstuffs
Make UNIX great again!
Poll close in
How many pairs of the why and the what in Mach are correct?
Whys v.s. whats
(1) (2) (3) (4)
Support for multiprocessors
Networked computing
OS Extensibility
Messages/Ports
Kernel debugger
Repetitive but confusing mechanisms Messages/Ports
A. 0 B. 1 C. 2 D. 3 E. 4
Poll close in
How many pairs of the why and the what in Mach are correct?
Whys v.s. whats
(1) (2) (3) (4)
Support for multiprocessors
Networked computing
OS Extensibility
Messages/Ports
Kernel debugger
Repetitive but confusing mechanisms Messages/Ports
A. 0 B. 1 C. 2 D. 3 E. 4
The hardware is changing
Multiprocessors
Why Mach?
Networked computing
The software
ThedemandofextendinganOSeasily
Repetitive but confusing mechanisms for similar stuffs
UNIX provides a variety of mechanisms Pipes
No protection
No consistency Location dependent
Interprocess communication
Port is an abstraction of:
Messagequeues
Capability
What do ports/messages promote?
Locationindependenceeverythingiscommunicatingwithports/ messages, no matter where it is
Ports/Messages
Ports/Messages
Capability of Z Message queues
read, write
Capability of A
read, write
message = something;
send(port Z, message);
Capability of B
read, write
recv(port Z, message);
What is capability? Hydra
An access control list associated with an object
Contains the following: Areferencetoanobject Alistofaccessrights
Whenever an operation is attempted:
Therequestersuppliesacapabilityofreferencingtherequesting
The OS kernel examines the access rights
Type-independant rights
Type-dependent rights
object like presenting the boarding pass
Poll close in
Tasks/Processes and threads
How many of the following regarding the comparison of parallelizing
computation tasks using processes and threads is/are correct?
! Thecontextswitchandcreationoverheadofprocessesishigher
Theoverheadofexchangingdataamongdifferentcomputingtasksforthe same applications is higher in process model
# Thedemandofmemoryusageishigherwhenusingprocesses
$ Thesecurityandisolationguaranteesarebetterachievedusingprocesses
Poll close in
Tasks/Processes and threads
How many of the following regarding the comparison of parallelizing
computation tasks using processes and threads is/are correct?
! Thecontextswitchandcreationoverheadofprocessesishigher
Theoverheadofexchangingdataamongdifferentcomputingtasksforthe same applications is higher in process model
# Thedemandofmemoryusageishigherwhenusingprocesses
$ Thesecurityandisolationguaranteesarebetterachievedusingprocesses
Intel Sandy Bridge
Share L3 $
Concept of chip multiprocessors
Core Core Registers Registers
L1-$ L1-$ L2-$ L2-$
Registers L2-$ L2-$
Last-level $ (LLC)
Main memory is eventually shared among processor
Main memory
Tasks/processes
PC CPU Memory
Each process has its own unique virtual memory address ace, it of execu set of I/O
s own states
tion, its own
static data
static data
heap Virtual memory
a = 0x01234567
heap Virtual memory
a = 0xDEADBEEF
static data
static data
heap Virtual memory
a = 0x87654321
heap Virtual memory
a = 0x95273310
Task#1 Thread #1 Thread #2
CPU PC CPU
Thread #3 Thread #1 Thread #2
CPU PC PC CPU PC CPU
Each process has its own unique virtual memory address
space, its own states of execution, its own set of I/Os
Each thread has its own PC, states of execution, but shares
memory address spaces, I/Os without threads within the
same process
static data
static data
heap Virtual memory
a = 0x01234567
heap Virtual memory
a = 0x01234567
Tasks/Processes and threads
How many of the following regarding the comparison of parallelizing
computation tasks using processes and threads is/are correct?
! Thecontextswitchandcreationoverheadofprocessesishigher
you have to change page tables, warm up TLBs, warm up caches, create a new memory space
Theoverheadofexchangingdataamongdifferentcomputingtasksforthe same applications is higher in process model
# Thedemandofmemoryusageishigherwhenusingprocesses
separate address, its not easy to access data from another process
you cannot directly share data without leveraging other mechanisms
each process needs its own address space even if most data are potentially identical
$ Thesecurityandisolationguaranteesarebetterachievedusingprocesses
Reading quizzes due next Tuesday
Welcomenewfriends!willdropatotalof6readingquizzesforthequarter Attendancecountas4readingquizzes
Weplantohaveatotalof11readingquizzes
Announcement
Office Hour links are inside Google Calendar events
https://calendar.google.com/calendar/u/0/r?
We will make both midterm and final exams online this quarter
AvoidtheuncertaintyofCOVID-19
Avoidhigh-densityintheclassroom(onlysits60andwehave59fornow)during examines
Different links from lecture ones
We cannot share through any public channels so that we can better avoid Zoom bombing
Engineering
CS: assignmentchef QQ: 1823890830 Email: [email protected]
Reviews
There are no reviews yet.