\documentclass[12pt]{article}
\usepackage{times}

\setlength{\textheight}{9in}
\setlength{\columnsep}{0.25in}
\setlength{\textwidth}{7in}
%\setlength{\footheight}{0.0in}
%\setlength{\topmargin}{0.25in}
\setlength{\headheight}{0.1in}
\setlength{\headsep}{0.2in}
\setlength{\oddsidemargin}{-.19in}
\setlength{\parindent}{1pc}

\voffset=-0.5in
\hoffset=-0.15in





\begin{document}

\hrule

\begin{center}
{\Large CMPSCI 677: Operating Systems}\\
{\bf Homework 1}\\
{Spring 2003}\\[.1in]

{\em Due:} Thursday, February 6 (in class). Off-campus students: one week 
from when you watch Lecture 2.
\end{center}
{\bf Note:} Feel free to use an undergraduate operating systems text as a reference 
for this assignment.\\

\hrule

\begin{enumerate}

\item True or false questions. Justify your
answer in one or two sentences.

\begin{enumerate}

\item   All interactive time-shared systems are also multiprogrammed systems.

\item  Traps are a common mechanism used by the OS to implement {\em all} of
the following: system call, page fault, and illegal memory access.



\item Only a parent process can kill a child process.

\item Kernel threads have faster context switches than user-level threads.

\item  Shared data that is only read but not written to by cooperating
threads need not be protected by a critical section.

\item A synchronization problem that requires counting semaphores can never
be implemented using locks.

\item Overlays allow contiguous memory allocation techniques to support
process sizes that are larger than the size of physical memory.
 


\item Compaction algorithms are required in a memory system that uses pure
segmentation.

\item Thrashing is less likely if you use a global page replacement scheme.

\item Direct memory access (DMA) transfers increase contention on the system bus. 

%\item A synchronization problem that requires counting semaphores can never
%be implemented using locks.


%\item Thrashing is less likely if you use a global page replacement scheme.

\end{enumerate}

\item Write short answers
\begin{enumerate}
\item  You are in charge of writing a device driver for a 56Kbps modem
on your PC. Assuming you decide to use {\em polling} for communication
between the OS   and the modem hardware, explain the steps involved in
writing a data packet from the OS to the modem.

\item  Since the shortest job first scheduling algorithm has provably optimal  
average waiting times, would you use it to schedule processes in a conventional
operating system. Why or why not?

\item  What is second chance page replacement and why
do many operating systems prefer it to LRU?

\item  Does Banker's algorithm do deadlock prevention or deadlock avoidance? Why? 

\item  Give a 1-2 sentence definition of a system call.


\item  Why does a pure paging scheme not suffer from external 
fragmentation?


\end{enumerate}




 
\item 

Consider  a precedence graph in which program segment $S_2$ must
execute only after $S_1$,  and $S_3$, $S_4$ and $S_5$ must execute only after $S_2$.

Assume that each of the $S_i$'s is executed
 in a separate process $P_i$. You may assume that the processes are
 unrelated (i.e., the processes need not be created), and that each
 process $P_i$ has exactly one computation step $S_i$.  Give the
pseudo-code for  the individual processes  using each of the
 following:
(a) Semaphores (b)
 Locks (c) UNIX fork() and waitpid() system calls.  Your C program
syntax need not be correct. But the use of the fork() and waitpid()
system calls must be correct. You should permit the maximum amount of
concurrency possible.
Also, discuss the appropriateness of monitors to achieve this synchronization.




\item  Write pseudo code to solve the following synchronization problem 
using locks. Consider a candy shop where each customer takes a number
and waits until a sales person calls their number.  The sales person
services customers in the order of their ticket numbers. Write two
routines {\em Enter} and {\em Service} to solve this problem using
locks`.  Assume that the {\em Enter} routine is used by each new
customer and the {\em Service} routine is used by the sales person to
service the next customer. Be sure to clearly declare and initialize
all variables.  How does your solution change if you were to use
semaphores instead?


\item 
Operating systems enforce protection using the notion of a domain and
by associating a set of access privileges with each domain. Many
operating systems also support a {\em domain switch} where an
application can begin execution in one domain and then switch to
another domain (and thereby acquire the privileges associated with tha
t domain). Give an example of an application that might benefit from
this feature.




\item \begin{itemize}
\item In standard uniprocessor {\tt Unix}, explain why the
following command will not produce a useful result. \\
  {\tt sort < foobar > foobar }
\item What (erroneous) result will it always produce ?


\item Why, and when, would the following command {\em sometimes} produce a
useful result? \\
  {\tt sort < foobar | ( cat > foobar ) } \\
where the paranthesis is {\tt sh}-ell notation to execute the
contained command in a sub-shell.  


\end{itemize}


\end{enumerate}
\end{document}





