Description
Lab 1
1. Write small c programs.
a). The first program “pre.c”
should read in a list of student names and their GPAs. To be simple, you can just input the
students’ first names. Enter the inputs through the keyboard and display the outputs on the screen.
The inputs end when an EOF (generated by Ctrl-D) is encountered. The outputs of the program should
display the students whose GPAs are above 3.0.
For example, the following are the inputs to “pre.c”.
Susan 3.1
John 2.0
David 3.5
Jessica 3.4
Ctrl-D (press the keys to terminate the inputs.)
then “pre.c” produces the output:
Susan
David
Jessica
Note: an EOF is usually ‘sent’ to a process by hitting a CTRL_D.
If you type stty -a on your unix command line, you can get info that
tells you which keyboard keys mean what. FYI, in c, to put values to
standard_out use printf(). To get values from standard_in use scanf()
or getchar().
b). The second program “sort.c” reads in a list of student names from the keyboard and
displays them in alphabetical order on the screen. Assume the sequence is read until
an EOF is encountered.
If the inputs are:
Susan
David
Jessica
Ctrl-D (press the keys to terminate the inputs.)
The outputs should be:
David
Jessica
Susan
2. Write a c program to set up a child-TO-parent pipe; the child
should ‘exec’ to perform a “pre” process and its output should be
connected to the pipe connected to the parent, which should ‘exec’ to
perform a “sort” process.
3. Write a program to take a UNIX command from the command line
and fork() a child to execute it. The command can be a simple
command like: $ls or $ps, Or it can be a command with options such as
$ls -t -l. Use argc and argv[] in the main function to pass parameters.
When the child process is executing the command, the parent process
simply waits for the termination of the child process. The process
id of the parent and the child should be printed out using getpid() and
getppid() functions.
Submission:
In order not to lose any files, you’d better zip all your files into a .zip file.
Submit your project to TRACS before the deadline. Homework will NOT be accepted
through emails. You should write a readme textfile telling the grader how to run
your programs. Without this file, it is very likely that your project will not be
run properly.
Project 3
Three students are competing for a scholarship of $4,000. Suppose the
scholarship is awarded in a FCFS fashion. Each time each one can get
25% of the available fund.
Use three threads to simulate this. Each thread should execute in a loop.
When the fund runs out, stop all the threads and terminate the program.
And then you add all the money given out, if the total does not add up
to $4000, your program is not correct.
a. Write the program without considering the mutual exclusion. Run the
program several times to show that mutual exclusion is not guaranteed and
the result is not correct.
b. Write the program again considering the mutual exclusion. Run the
program several times to show that mutual exclusion is guaranteed.
To make longer execution of threads, use some sleep(n) functions in
the program. Experiment with n to choose the best one to show the
results.
The following is an example. Your results may not be exactly the same.
Example of an incorrect result:
A=1000
B=750
C=750
B=375
A=375
…
Finally, the total money given out is not equal to $4000.
Example of a correct result:
A=1000
B=750
C=563 (round up to the ceiling of the number if the result is not an integer)
A=422
C=317
B=237
A=178
A=134
B=100
C=75
B=56
C=42
A=32
C=24
B=18
C=13
C=10
A=8
C=6
B=4
A=3
A=2
B=2
C=1
B=1
C=1
A=1
Total given out: 4000
Submission:
In order not to lose any files, you’d better zip all your files into a .zip file.
Submit your project to TRACS before the deadline. Homework will NOT be accepted
through emails. You should write a readme textfile telling the grader how to run
your programs. Without this file, it is very likely that your project will not be
run properly.
Lab 4
Write a program to compare the performance of the LRU and the Optimal page replacement
algorithms. The program will take a reference string and the number of frames as inputs.
Assume the maximum length of a reference string is 20 and there are 5 diffent pages from
page 1 to page 5. The reference string can be randomly generated and the number of frames
is entered through the keyboard. For example, the system generates a reference string
2 1 3 4 5 2 3 …5 and you enter the number of frames 3. Compare the number of page
faults generated by the Optimal and LRU algorithms. Print out the page replacement process
and you can see how LRU differs from the optimal.
Submission:
In order not to lose any files, you’d better zip all your files into a .zip file.
Submit your project to TRACS before the deadline. Homework will NOT be accepted
through emails. You should write a readme textfile telling the grader how to run
your programs. Without this file, it is very likely that your project will not be
run properly.



