1. Answer True/False (T/F) (1 point each)
____ The threads in a process share the same stack.
____ ELF is an executable format used on Windows.
____ truss is a UNIX command to show the number of users in the system.
____ The text section of a program is memory mapped readable and executable.
____ System calls and interrupts run in user mode.
____ There may be three running process in a dual processor computer.
____ Most of the CPU time is spent in user mode.
____ Shared libraries run in user mode.
____ A small time quantum will cause a program to take more time.
____ The arguments of a system call are checked in user space.
____In preemptive scheduling a process takes higher priority until
completion.
____ A program that runs with preemptive scheduling runs faster than
one in non-preemptive scheduling.
____ Most of the processes' CPU bursts are completed before the time
quantum expires.
____ Programs that run with FCFS have a higher response time than SJF.
____ The file descriptors of a process are closed when the process
calls fork().
____ The write() function is a system call but printf() is not.
____ A pipe that is used to communicate a parent and a child process
could be created by the child.
____ Threads in the same process share the same memory.
____ A section of code that is guarded by mutex_lock()/mutex_unlock()
can be executed by only one thread at a time.
____The process table contains a set of registers and program counters
for each user and kernel level thread in a process.
2. (4 pts.) What is a real-time system, a hard real-time system, and
a soft real-time system?
3. (4 pts.) Why system calls use software interrupts and not normal
function calls.
4. (4 pts.) What are the steps for servicing an interrupt?
5. (4 pts.) In which state processes are most of the time and in what
kind of programs this is not true?
6. (4 pts.) What are the advantages and disadvantages of using threads
vs. using processes?
7. (4 pts.) What factors have to be considered when choosing the
length of a quantum time?
8. (8 pts.) Assume that a computer executes the following jobs:
Process | Time needed for completion (ms) |
P1 | 50 |
P2 | 5 |
P3 | 25 |
Compute the average waiting time if the following scheduling algorithms are used:
FCFS:
SJF:
Round Robin Preemptive scheduling (Quantum=10ms):
9. (6 pts.) Mark the "C" expressions that are quivalent to a[i]. The type of a[i] is <type of a[0]> | ||||||||||||||||||||||
|
10. (6 pts.) The following class implements a multi-threaded stack. The push() and pop() calls can be called simultaneously by different threads. Insert the necessary code and member variables so multiple threads can run the stack operations simultaneously without corrupting the stack. |
class Stack { int stackPointer;
public: void
stack[ stackPointer ] = a;
} int
stackPointer--;
return tmp;
Stack::Stack() {
}
};
|
11. (13 pts.) Complete the procedure redirectStdout( fileName ) to redirect the standard out to file fileName. The procedure will return -1 if any error occurrs or 0 if it succeeds. Look at main() to see how redirectStdout( ) is used. Also write the procedure restoreOutput() that will restore the output to the way it was before calling redirectStdout. Notice that the procedure is called redirectStdout and not redirectStdin. |
int redirectStdout( char * fileName )
} int restoreStdout() {
} main()
printf( "This Hello world will be printed to myfile\n" ); restoreStdout(); printf( "This Hello World will be printed to the screen\n"); }
|
12. (13 pts.) Complete the procedure runCommand( command, outputBuffer, bufferSize) that executes a command in a different process and stores its output in outputBuffer. command is the name of the program with no arguments. See how main uses runCommand(). runCommand will return 0 on success or -1 otherwise. |
int
runCommand( char * command, char * outputBuffer, int maxBufferSize) { } int
if ( runCommand(
"ls", buffer, 1024 ) < 0 ) {
printf( "ls: %s\n", buffer ); exit( 0 );
|
13. (10 pts.) Write the code for the function strcat(). |
char * strcat( char * dest, char * src )
{ }
|