



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




My name looks like this when printed very clearly: _____________ _
Answer all questions! Pay attention to point totals. The last page has a list of Unix system calls.
Sys. prog 1) 10 pts:
We want to write a program that generates and prints out a bunch of random numbers in sorted order. Instead of sorting the numbers ourselves, we will use I Ulilr Ibinl sort -n to do the sorting for us (the -n flag tells sort to order the lines numerically instead of alphabetically). Below is code that will print out a bunch of random numbers, your job is to add code so that the output ofthis program goes to '/usr/bin/sort -n" which will print the numbers in order.
Show that code that should be added in the section labeled "your code goes here" that will send the output from the printf statements to sort -n. Don't change anything else in the program!
#include <stdio.h> #include <stdlib.h> #include <unistd.h>
int main(int argc, ehar **argv) { int n;
if (arge==l) n=10;
arrange things so that printf output to sort -n
Page #
A pipeline of commands can be built using pipes (like we did in the shell). In some older operating systems (DOS), the shell supported the idea of pipelining, but the operating system did not actually support pipes. The shell would create a temporary file in which the first program stores itls output, and then the second program would read from the same file. This is not nearly as nice as having real pipes (in general you donlt have both processes running at the same time, like you would with a real pipeline), but it is still useful.
Your job is to write a C program that runs the command line "/usr/bin/who I /usr/bin/sort -r" by using a temporary file instead of a pipe. The result is effectively like running" /usr/bin/who > tempfile" followed by "/usr/bin/sort -r < tempfile". Donlt worry about includes or error handling, you should do your best to make sure each system call made by your program is done correctly there is a list of system call prototypes at the end of this test. We want C code, not pseudo col\e! Your prQl:lTam must not use pipes, and you must use some form of execO - no shortcuts using system ( )
J/:bTpd)d
fJ!:~( ~/~J!~~AlLY);
Page #
~----~-.----.---.---
MeroQ[y 3) 5 pts: Briefly describe a working set and the working set page replacement algorithm. ~ ~ ~
-l4.~~.::~" '. ~~u-d4.~~ ~/~uJ~';"'~A.~~'~~~./4. .~ ~c4 ~cad~~ _...._ ~dct~~U<iY~ OpSys Spring 2008 - Test 2 Page # #### 15 pts: Provide a high-Iev~l description of each of the following strategles·^ fior mem^ ory management: ('" • system based on swapping ~ '\ -; • paged virtual memo", *~ _ __4/J_ - "gmented m"""'Y , ~ ~ ~ ~~ ~:~~ ~~~-~~ ~ ~tH£. ~. **''-;-** ~AM~ ~~4: ~~ ~ ~~~-----i? ~ ~~~~A1q-~~ OpSys Spring 2008 Test 2 Page #