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

Post on 29-Dec-2015

217 views 2 download

Tags:

Transcript of Solutions to the first midterm COSC 4330/6310 Summer 2012.

Solutions to the first Solutions to the first midtermmidterm

COSC 4330/6310COSC 4330/6310

Summer 2012Summer 2012

First question: True or falseFirst question: True or false

Processes waiting for the CPU are in the Processes waiting for the CPU are in the waitingwaiting state. state.

First question: True or falseFirst question: True or false

Processes waiting for the CPU are in the Processes waiting for the CPU are in the waitingwaiting state. state.

FALSEFALSE, they are in the , they are in the ready stateready state

First question: True or falseFirst question: True or false

UNIX was the first system to be written in CUNIX was the first system to be written in C..

First question: True or falseFirst question: True or false

UNIX was the first system to be written in CUNIX was the first system to be written in C..

TRUETRUE, it was designed to be portable, it was designed to be portable(and C was specifically written for UNIX)(and C was specifically written for UNIX)

First question: True or falseFirst question: True or false

Memory protection is always Memory protection is always implemented in hardware.implemented in hardware.

First question: True or falseFirst question: True or false

Memory protection is always implemented Memory protection is always implemented in hardware.in hardware.

TRUE, any other solution would be too slowTRUE, any other solution would be too slow

First question: True or falseFirst question: True or false

execve()execve() system calls are often followed by system calls are often followed by a a fork()fork() system call. system call.

First question: True or falseFirst question: True or false

execve()execve() system calls are often followed by system calls are often followed by a a fork()fork() system call. system call.

FALSE, it is the other way around:FALSE, it is the other way around:

fork()fork() system calls are often followed by system calls are often followed by an an execve() execve() system call. system call.

First question: True or falseFirst question: True or false

In a In a multiprogramming systemmultiprogramming system, there can , there can be be many programsmany programs in the system but only in the system but only one processone process . .

First question: True or falseFirst question: True or false

In a In a multiprogramming systemmultiprogramming system, there can , there can be be many programsmany programs in the system but only in the system but only one processone process . .

FALSEFALSE, there are many processes , there are many processes competing for one of the CPU cores competing for one of the CPU cores

First question: True or falseFirst question: True or false

Most modern operating systems have a Most modern operating systems have a microkernel.microkernel.

First question: True or falseFirst question: True or false

Most modern operating systems have a Most modern operating systems have a microkernel.microkernel.

FALSEFALSE, microkernels are too slow , microkernels are too slow

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major disadvantage ofWhat is the major disadvantage of modular modular kernels kernels overover monolithic kernels monolithic kernels??

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major disadvantage ofWhat is the major disadvantage of modular modular kernels kernels overover monolithic kernels monolithic kernels??

They make the kernel less robust. They make the kernel less robust.

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major advantage ofWhat is the major advantage of modular modular kernels kernels overover monolithic kernels monolithic kernels??

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major advantage ofWhat is the major advantage of modular modular kernels kernels overover monolithic kernels monolithic kernels??

They let users add functionality to the kernels They let users add functionality to the kernels like new file systems or device drivers for like new file systems or device drivers for new devices new devices

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major disadvantage ofWhat is the major disadvantage of CPUs that CPUs that do do notnot have a have a privileged modeprivileged mode??

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major disadvantage ofWhat is the major disadvantage of CPUs that CPUs that do do notnot have a have a privileged modeprivileged mode??

They cannot prevent user processes from They cannot prevent user processes from executing I/O instructions executing I/O instructions

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major disadvantage of What is the major disadvantage of not not having memory protectionhaving memory protection??

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major disadvantage of What is the major disadvantage of not not having memory protectionhaving memory protection??

We cannot prevent user processes from We cannot prevent user processes from tampering with the kernel (and other user tampering with the kernel (and other user processes) processes)

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major advantage ofWhat is the major advantage of user-level user-level threadsthreads??

Second question:Second question:Advantages and disadvantagesAdvantages and disadvantages

What is the major advantage ofWhat is the major advantage of user-level user-level threadsthreads??

They are portable and can run on kernels They are portable and can run on kernels that do not support threads.that do not support threads.

Third question: I/O redirectionThird question: I/O redirection

Complete the following fragment of code to Complete the following fragment of code to ensure that the ensure that the standard inputstandard input of the of the process is redirected to the pipe process is redirected to the pipe mypipemypipe. .

int fd, mypipe[2];int fd, mypipe[2];______________________________________________________________________________________________________close(mypipe[0]); close(mypipe[1]);close(mypipe[0]); close(mypipe[1]);

Third question: I/O redirectionThird question: I/O redirection

Complete the following fragment of code to Complete the following fragment of code to ensure that the ensure that the standard inputstandard input of the of the process is redirected to the pipe process is redirected to the pipe mypipemypipe. .

int fd, mypipe[2];int fd, mypipe[2];pipe(mypipe);pipe(mypipe);close(0); dup(mypipe[0];close(0); dup(mypipe[0];close(mypipe[0]); close(mypipe[1]);close(mypipe[0]); close(mypipe[1]);

Third question: I/O redirectionThird question: I/O redirection

Complete the following fragment of code to Complete the following fragment of code to ensure that the ensure that the standard outputstandard output of the of the process is redirected to the pipe process is redirected to the pipe mypipemypipe. .

int fd, mypipe[2];int fd, mypipe[2];______________________________________________________________________________________________________close(mypipe[0]); close(mypipe[1]);close(mypipe[0]); close(mypipe[1]);

Third question: I/O redirectionThird question: I/O redirection

Complete the following fragment of code to Complete the following fragment of code to ensure that the ensure that the standard outputstandard output of the of the process is redirected to the pipe process is redirected to the pipe mypipemypipe. .

int fd, mypipe[2];int fd, mypipe[2];pipe(mypipe);pipe(mypipe);close(1); dup(mypipe[1];close(1); dup(mypipe[1];close(mypipe[0]); close(mypipe[1]);close(mypipe[0]); close(mypipe[1]);

Fourth questionFourth question How many lines of output will the following program How many lines of output will the following program

print? (5 points)print? (5 points)

int main(){int main(){

if (fork() == 0)if (fork() == 0)

printf("Hello World!\n");printf("Hello World!\n");

printf("Goodbye!\n")printf("Goodbye!\n")

} // main} // main

__________lines__________lines

Fourth questionFourth question How many lines of output will the following program How many lines of output will the following program

print? (5 points)print? (5 points)

int main(){int main(){

if (fork() == 0)if (fork() == 0)

printf("Hello World!\n");printf("Hello World!\n");

printf("Goodbye!\n")printf("Goodbye!\n")

} // main} // main

Three linesThree lines

Fifth questionFifth question

Give an example of a real time process withGive an example of a real time process with soft deadlinessoft deadlines..

Fifth questionFifth question

Give an example of a real time process Give an example of a real time process with with soft deadlinessoft deadlines..

A DVD playerA DVD player

Sixth questionSixth question

What is happening when a UNIX process What is happening when a UNIX process issues a wait() system call and all its child issues a wait() system call and all its child processes have already terminated?processes have already terminated?

Will the process wait forever? Will the process wait forever?

Sixth questionSixth question What is happening when a UNIX process issues What is happening when a UNIX process issues

a wait() system call and all its child processes a wait() system call and all its child processes have already terminated?have already terminated?

Will the process wait forever? Will the process wait forever?

NO, processes that have terminated but have not NO, processes that have terminated but have not yet been waited for by their parents remain in the yet been waited for by their parents remain in the process table in the ZOMBIE state.process table in the ZOMBIE state.

The waiting process returns immediatelyThe waiting process returns immediately

Seventh questionSeventh question

Which UNIX system call can we use to Which UNIX system call can we use to catch signals? What does it mean? Is it catch signals? What does it mean? Is it always possible? always possible?

Seventh questionSeventh question Which UNIX system call can we use to Which UNIX system call can we use to

catch signals? What does it mean? Is it catch signals? What does it mean? Is it always possible?always possible?

signal(…)signal(…) signal specifies what the process should do signal specifies what the process should do

when it receives a specific signalwhen it receives a specific signal No signal number 9 (SIGKIL) cannot be No signal number 9 (SIGKIL) cannot be

caught caught

Eighth questionEighth question

Why should we Why should we prevent prevent users of a multi-users of a multi-user system from user system from rebootingrebooting the OS from the OS from their own CD-ROM?their own CD-ROM?

Eighth questionEighth question

Why should we Why should we prevent prevent users of a multi-users of a multi-user system from user system from rebootingrebooting the OS from the OS from their own CD-ROM?their own CD-ROM?

User could reboot the system with an OS User could reboot the system with an OS that will let do things they are not authorized that will let do things they are not authorized to doto do