<!doctype html public "-//w3c//dtd html 4.0
transitional//en">
CS 471
Operating Systems
Spring 2012
Final Exam
Time 2 & 1/2 hours
Open Book & Notes
Name:
Unix Login:
All questions are of equal
weights.
Question
1:
The following is an outline of chat client program:
int main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
struct hostent *hp, *gethostbyname();
sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
hp = gethostbyname(argv[1]);
bcopy(hp->h_addr, &(servaddr.sin_addr.s_addr),
hp->h_length);
servaddr.sin_family
= AF_INET;
servaddr.sin_port
= htons(atoi(argv[2]));
if (connect(sockfd, (SA *) & servaddr, sizeof(servaddr)) < 0) {
perror("connect
error");
exit(-1);
}
Handle(0, sockfd);
}
A.
We have described five different implementations for the Handle function.
Briefly
describe these five implementations
B.
Give the detailed code one Implementation.
Question 2
A.
Assume we have program size of 9 pages and
its 100 reference sequence is:
7
5 5 8 9 3 9 2 9 6 1 1 1 4 8 6 3 5 6 5 4 3 3 3 2
6 1 8 9 3 2 5 7 6 8 8
4 7 4 2 1 8 9 9 8 7 4 9 3 8
8 8 8 7 5 9 3 3 5 7 7 9 7 1 3 3 4 7 1 2 9 2 6 7 9
6 4 9 4 3 4 4 5 7 5
3 2 3 5 1 2 5 6 2 8 3 7 1 1 2
Fill
in the number of page faults in the following matrix:
W
| OP FF
LR MR LF
MF RN
1 |
9 |
B.
Assume we have program size of 9 pages
and its reference sequence is:
6
8 5 2 8 7 1 7 3 3 5 8 6 3 6
Fill
in the number of page faults in the following matrix:
W
| OP FF
LR MR LF
MF
5 |
6 |
C. Can you detect Belady’s
Anomaly in B.
Question 3
A. Calculate the total head movement for servicing the following
request Queue according to the specified disk I/O scheduling algorithms.
Request
Queue (cylinder range 0-100): 95 35 125 25
Head
pointer: cylinder
45
|
Disk
Scheduling Algorithm |
FCFS |
SSTF |
|
Total Head Movement |
|
|
B.
Consider the
following program:
char *fname;
main(int argc, char *argv[])
{
fname = "QFileLock.c";
if (fork()) ReadFunction(1);
else if (fork()) WriteFunction(1);
else if (fork()) WriteFunction(2);
else if (fork()) ReadFunction(2);
pause();
}
void ReadFunction(int i)
{
int MyIndex
= i;
int fd;
if ((fd = open(fname,
O_RDONLY)) < 0) {
perror(fname);
exit(1);
}
printf("Reader
%d request read lock\n", MyIndex);
read_lock(fd);
printf("Reader
%d obtained read lock\n", MyIndex);
printf("Reader
%d sleeping 2 seconeds while read locked ...\n",
MyIndex);
sleep(2);
unlock(fd);
printf("Reader
%d Done...\n", MyIndex);
pause();
}
void WriteFunction(int i)
{
int MyIndex
= i;
int fd;
if ((fd = open(fname,
O_WRONLY)) < 0) {
perror(fname);
exit(1);
}
printf("Writer
%d request write lock\n", MyIndex);
write_lock(fd);
printf("Writer
%d obtained write lock\n", MyIndex);
printf("Writer
%d sleeping 2 seconeds while write locked
...\n", MyIndex);
sleep(2);
unlock(fd);
printf("Writer
%d Done...\n", MyIndex);
pause();
}
What is the output the
following command:
% QFileLock
Question 4
A.
Consider the following program:
main(int argc,
char *argv[])
{
int fd;
char *fname;
fname = argv[1];
if ((fd =
open(fname, O_RDWR)) == -1) {
printf("error
openning: %s\n", fname);
exit(-1);
} else {
printf("opened
%s\n", fname);
printf("fd is %d\n", fd);
exit(0);
}
}
What is the output of the following statements?
%
touch /tmp/Q4TestFile
%
Q4 /tmp/Q4TestFile
%
rm /tmp/Q4TestFile
%
Q4 /tmp/Q4TestFile
B.
What is the output
of the last 5 commands:
% touch /tmp/Q4TestFile /tmp/f1 /tmp/f2 /tmp/f3
% rm /tmp/Q4testfile /tmp/f1 /tmp/f2 /tmp/f3
% echo Wahab
> /tmp/Q4TestFile
% cp /tmp/Q4TestFile /tmp/f1
% ln /tmp/Q4TestFile /tmp/f2
% ln -s /tmp/Q4TestFile /tmp/f3
% ls –l /tmp/Q4TestFile
-rw------- 2 cs471w cs471w 6 2012-04-15 22:19 /tmp/Q4TestFile
% rm /tmp/Q4TestFile
% ls
–l /tmp/f1
% ls
–l /tmp/f2
% cat
/tmp/f1
% cat
/tmp/f2
% cat
/tmp/f3
Question 5
A. Consider the following commands:
% who am i
wahab pts/7 Apr 15 14:40 (dhcp-154.cs.odu.edu)
% ls
-lt /usr/bin/passwd
-r-sr-sr-x 1 root sys
27244 Aug 7 2009 /usr/bin/passwd
% passwd
passwd: Changing
password for wahab
Enter existing login
password:
During the execution of
passwd command, What is the output of the following command?
ps -a -o user,ruser,comm
| grep passwd
B. Consider
the following access matrix.

Is it
possible for D1 to read F2?
Explain.
A.
What is the value of
cipher message C corresponding to
message M = 6 encrypted with K = 3 using XOR
?
B.
What is the value of
cipher message C corresponding to
message M = 2 encrypted with the public key (5, 91) ?