Upload
lilian-edwards
View
212
Download
0
Embed Size (px)
Citation preview
Solutions to the first Solutions to the first midtermmidterm
COSC 4330/6310COSC 4330/6310
Summer 2013Summer 2013
First questionFirst question
a)a) Give an example of a popular operating Give an example of a popular operating system using a UNIX or a Linux kernel.system using a UNIX or a Linux kernel.
b)b) Give an example of a Give an example of a real-time processreal-time process with with hard deadlineshard deadlines. .
First questionFirst question
a)a) Give an example of a popular operating Give an example of a popular operating system using a UNIX or a Linux kernel.system using a UNIX or a Linux kernel.
Mac OS X or AndroidMac OS X or Android
b)b) Give an example of a Give an example of a real-time processreal-time process with with hard deadlineshard deadlines. .
First questionFirst question
a)a) Give an example of a popular operating Give an example of a popular operating system using a UNIX or a Linux kernel.system using a UNIX or a Linux kernel.
Mac OS X or AndroidMac OS X or Android
b)b) Give an example of a Give an example of a real-time processreal-time process with with hard deadlineshard deadlines. .
Industrial process control,Industrial process control,missile guidance system,missile guidance system,......
First questionFirst question
c)c) What is the main disadvantage of What is the main disadvantage of microkernelsmicrokernels??
d)d) What is the main advantage of What is the main advantage of delayed delayed writeswrites? ?
First questionFirst question
c)c) What is the main disadvantage of What is the main disadvantage of microkernelsmicrokernels??
They They are slower than other kernel are slower than other kernel organizations organizations
d)d) What is the main advantage of What is the main advantage of delayed delayed writeswrites? ?
First questionFirst question
c)c) What is the main disadvantage of What is the main disadvantage of microkernelsmicrokernels??
They They are slower than other kernel are slower than other kernel organizations organizations
d)d) What is the main advantage of What is the main advantage of delayed writesdelayed writes? ?
They reduce the number of disk accessesThey reduce the number of disk accesses They return faster They return faster
First questionFirst question
e)e) Where was the first operating system with a Where was the first operating system with a graphical user interface developed?graphical user interface developed?
f)f) Which event(s) will move a process from the Which event(s) will move a process from the waitingwaiting state state to the to the ready statready statee? ?
First questionFirst question
e)e) Where was the first operating system with a Where was the first operating system with a graphical user interface developed?graphical user interface developed?
At Xerox Palo Alto Research CenterAt Xerox Palo Alto Research Center(Xerox PARC)(Xerox PARC)
f)f) Which event(s) will move a process from the Which event(s) will move a process from the waitingwaiting state state to the to the ready statready statee? ?
First questionFirst question
e)e) Where was the first operating system with a Where was the first operating system with a graphical user interface developed?graphical user interface developed?
At Xerox Palo Alto Research CenterAt Xerox Palo Alto Research Center(Xerox PARC)(Xerox PARC)
f)f) Which event(s) will move a process from the Which event(s) will move a process from the waitingwaiting state state to the to the ready statready statee? ?
Whenever a system request issued by Whenever a system request issued by the process completesthe process completes
Second questionSecond question
What would be the What would be the main disadvantagemain disadvantage of a of a processor that would not have (3×5 points)processor that would not have (3×5 points)
a)a) Separate Separate supervisorsupervisor and and user modesuser modes??
b)b) Memory protectionMemory protection??
c)c) Timer interruptsTimer interrupts??
Second questionSecond question
What would be the What would be the main disadvantagemain disadvantage of a of a processor that would not have (3×5 points)processor that would not have (3×5 points)
a)a) Separate Separate supervisorsupervisor and and user modesuser modes?? We could not prevent user programs We could not prevent user programs
from directly accessing the diskfrom directly accessing the diskb)b) Memory protectionMemory protection??
c)c) Timer interruptsTimer interrupts??
Second questionSecond question
What would be the What would be the main disadvantagemain disadvantage of a of a processor that would not have (3×5 points)processor that would not have (3×5 points)
a)a) Separate Separate supervisorsupervisor and and user modesuser modes?? We could not prevent user programs We could not prevent user programs
from directly accessing the diskfrom directly accessing the diskb)b) Memory protectionMemory protection??
We could not prevent user programs We could not prevent user programs from corrupting the kernelfrom corrupting the kernel
c)c) Timer interruptsTimer interrupts??
Second questionSecond question
What would be the What would be the main disadvantagemain disadvantage of a of a processor that would not have (3×5 points)processor that would not have (3×5 points)
a)a) Separate Separate supervisorsupervisor and and user modesuser modes?? We could not prevent user programs from We could not prevent user programs from
directly accessing the diskdirectly accessing the diskb)b) Memory protectionMemory protection??
We could not prevent user programs from We could not prevent user programs from corrupting the kernelcorrupting the kernel
c)c) Timer interruptsTimer interrupts?? We could not prevent user programs from We could not prevent user programs from
monopolizing the CPUmonopolizing the CPU
Third questionThird question
Add the missing code to the following Add the missing code to the following program to ensure it will program to ensure it will alwaysalways print: print:
• Child says hello!Child says hello!Parent says hello!Parent says hello!
in that in that exact orderexact order. (3×5 points). (3×5 points)
The programThe program
#include <unistd.h>#include <unistd.h>#include <stdio.h>#include <stdio.h>void main() {void main() {
int pid;int pid;if ((pid = fork()) == _____) {if ((pid = fork()) == _____) {
printf("Child says hello!\n");printf("Child says hello!\n");__________________________;__________________________;
} // if} // if_______________________________;_______________________________;printf("Parent says hello!\n");printf("Parent says hello!\n");
} // main} // main
The programThe program
#include <unistd.h>#include <unistd.h>#include <stdio.h>#include <stdio.h>void main() {void main() {
int pid;int pid;if ((pid = fork()) == __if ((pid = fork()) == __00__) {__) {
printf("Child says hello!\n");printf("Child says hello!\n");__________________________;__________________________;
} // if} // if_______________________________;_______________________________;printf("Parent says hello!\n");printf("Parent says hello!\n");
} // main} // main
The programThe program
#include <unistd.h>#include <unistd.h>#include <stdio.h>#include <stdio.h>void main() {void main() {
int pid;int pid;if ((pid = fork()) == if ((pid = fork()) == 00 ) { ) {
printf("Child says hello!\n");printf("Child says hello!\n");_exit(0)_exit(0); ; // to terminate the child// to terminate the child
} // if} // if________________________;________________________;printf("Parent says hello!\n");printf("Parent says hello!\n");
} // main} // main
The programThe program
#include <unistd.h>#include <unistd.h>#include <stdio.h>#include <stdio.h>void main() {void main() {
int pid;int pid;if ((pid = fork()) == if ((pid = fork()) == 00 ) { ) {
printf("Child says hello!\n");printf("Child says hello!\n");_exit(0)_exit(0); ; // to terminate the child// to terminate the child
} // if} // ifwait(0); // wait first for child completionwait(0); // wait first for child completionprintf("Parent says hello!\n");printf("Parent says hello!\n");
} // main} // main
Fourth questionFourth question
What does a program do when it receives a What does a program do when it receives a signal? (5 points)signal? (5 points)
What can we do to change this behavior? (5 What can we do to change this behavior? (5 points)points)
Is it always possible? (5 points)Is it always possible? (5 points)
Fourth questionFourth question
What does a process do when it receives a What does a process do when it receives a signal? (5 points)signal? (5 points)
It terminatesIt terminates
What can we do to change this behavior? (5 What can we do to change this behavior? (5 points)points)
Is it always possible? (5 points)Is it always possible? (5 points)
Fourth questionFourth question
What does a process do when it receivesWhat does a process do when it receives a signal? (5 points) a signal? (5 points)
It terminatesIt terminates
What can we do to change this behavior? What can we do to change this behavior? (5 points)(5 points)
Process can catch the signal using Process can catch the signal using signal()signal()
Is it always possible? (5 points)Is it always possible? (5 points)
Fourth questionFourth question
What does a process do when it receivesWhat does a process do when it receives a signal? (5 points) a signal? (5 points)
It terminatesIt terminates
What can we do to change this behavior? (5 What can we do to change this behavior? (5 points)points)
Process can catch the signal using Process can catch the signal using signal(…) systeem callsignal(…) systeem call
Is it always possible? (5 points)Is it always possible? (5 points)
SIGKIL signal cannot be caughtSIGKIL signal cannot be caught
Fifth questionFifth question
How will the following code fragment affectHow will the following code fragment affect stdinstdin,, stdout stdout and and stderrstderr?? (3×5 points)(3×5 points)
The codeThe code
int fda, fdb;int fda, fdb;fda = open("alpha", O_RDWR | O_CREAT, 0640); fda = open("alpha", O_RDWR | O_CREAT, 0640);
fdb = open("beta" , O_RDWR | O_CREAT, 0640);fdb = open("beta" , O_RDWR | O_CREAT, 0640);close(0);close(0);dup(fda);dup(fda);close(1);close(1);dup(fdb);dup(fdb);
The codeThe code
int fda, fdb;int fda, fdb;fda = open("alpha", O_RDWR | O_CREAT, 0640); fda = open("alpha", O_RDWR | O_CREAT, 0640);
fdb = open("beta" , O_RDWR | O_CREAT, 0640);fdb = open("beta" , O_RDWR | O_CREAT, 0640);close(0);close(0);dup(fda); dup(fda); // fda duplicated into stdin// fda duplicated into stdinclose(1);close(1);dup(fdb);dup(fdb);
stdin will read from file "alpha" stdin will read from file "alpha"
The codeThe code
int fda, fdb;int fda, fdb;fda = open("alpha", O_RDWR | O_CREAT, 0640); fda = open("alpha", O_RDWR | O_CREAT, 0640); fdb = open("beta" , O_RDWR | O_CREAT, 0640);fdb = open("beta" , O_RDWR | O_CREAT, 0640);close(0);close(0);dup(fda); dup(fda); // fda duplicated into stdin// fda duplicated into stdinclose(1);close(1);dup(fdb); dup(fdb); // fdb duplicated into stdout// fdb duplicated into stdout
stdin will read from file "alpha" stdin will read from file "alpha" stdout will be redirected to file "beta"stdout will be redirected to file "beta"
The codeThe code
int fda, fdb;int fda, fdb;fda = open("alpha", O_RDWR | O_CREAT, 0640); fda = open("alpha", O_RDWR | O_CREAT, 0640); fdb = open("beta" , O_RDWR | O_CREAT, 0640);fdb = open("beta" , O_RDWR | O_CREAT, 0640);close(0);close(0);dup(fda); dup(fda); // fda duplicated into stdin// fda duplicated into stdinclose(1);close(1);dup(fdb); dup(fdb); // fdb duplicated into stdout// fdb duplicated into stdout
stdin will read from file "alpha" stdin will read from file "alpha" stdout will be redirected to file "beta"stdout will be redirected to file "beta"stderr will be unchangedstderr will be unchanged
Sixth questionSixth question
What happens when aWhat happens when a user-level thread user-level thread does a does a blocking system callblocking system call? (5 points)? (5 points)
What can we do to avoid that? (5 points)What can we do to avoid that? (5 points)
Sixth questionSixth question
What happens when aWhat happens when a user-level thread user-level thread does a does a blocking system callblocking system call? (5 points)? (5 points)
• The CPU scheduler will put the whole The CPU scheduler will put the whole process into the waiting state even process into the waiting state even when other threads are ready to runwhen other threads are ready to run
What can we do to avoid that? (5 points)What can we do to avoid that? (5 points)
Sixth questionSixth question
What happens when aWhat happens when a user-level thread user-level thread does does a a blocking system callblocking system call? (5 points)? (5 points)
• The CPU scheduler will put the whole The CPU scheduler will put the whole process into the waiting state even when process into the waiting state even when other threads are ready to runother threads are ready to run
What can we do to avoid that? (5 points)What can we do to avoid that? (5 points)
The programmer cannot use blocking The programmer cannot use blocking system callssystem calls
Use kernel-supported threadsUse kernel-supported threads