+ All Categories
Home > Documents > Solutions to the first midterm COSC 4330/6310 Summer 2013.

Solutions to the first midterm COSC 4330/6310 Summer 2013.

Date post: 12-Jan-2016
Category:
Upload: lilian-edwards
View: 213 times
Download: 0 times
Share this document with a friend
31
Solutions to the Solutions to the first midterm first midterm COSC 4330/6310 COSC 4330/6310 Summer 2013 Summer 2013
Transcript
Page 1: Solutions to the first midterm COSC 4330/6310 Summer 2013.

Solutions to the first Solutions to the first midtermmidterm

COSC 4330/6310COSC 4330/6310

Summer 2013Summer 2013

Page 2: Solutions to the first midterm COSC 4330/6310 Summer 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. .

Page 3: Solutions to the first midterm COSC 4330/6310 Summer 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.

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. .

Page 4: Solutions to the first midterm COSC 4330/6310 Summer 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.

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,......

Page 5: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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? ?

Page 6: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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? ?

Page 7: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 8: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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? ?

Page 9: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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? ?

Page 10: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 11: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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??

Page 12: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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??

Page 13: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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??

Page 14: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 15: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 16: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 17: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 18: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 19: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 20: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 21: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 22: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 23: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 24: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 25: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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);

Page 26: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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"

Page 27: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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"

Page 28: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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

Page 29: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 30: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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)

Page 31: Solutions to the first midterm COSC 4330/6310 Summer 2013.

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


Recommended