CS3161 Operating System Principles

advertisement
CS3161 Operating System Principles
Fall 2007
Homework 1
Due Oct 8th, 2007
1. Describe the difference between the client–server and peer-to-peer models of
distributed systems.
2. Describe the operating system's two modes of operation.
3. Describe the relationship between an API, the system-call interface, and the operating
system.
4. On a unix machine, run command “truss touch aaa” and get the output of the
command, please explain what each step does. What are these fuctions? What is the
function similar to “truss” on linux?
5. The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .... Formally,
it can be expressed as:
f ib0 = 0
f ib1 = 1
f ibn = f ibn−1 + f ibn−2
Write a multithreaded program that generates the Fibonacci series using Pthread thread
library. This program should work as follows: The user will enter on the command line
the number of Fibonacci numbers that the program is to generate. The program will then
create a separate thread that will generate the Fibonacci numbers, placing the sequence in
data that is shared by the threads (an array is probably the most convenient data
structure).When the thread finishes execution, the parent thread will output the sequence
generated by the child thread. Because the parent thread cannot begin outputting the
Fibonacci sequence until the child thread finishes. An example Thread.c program is
attached at the end which can be used as a template.
6. Consider the following set of processes, with the length of the CPU-burst time given in
milliseconds:
Process Burst Time Priority
Process
P1
P2
P3
P4
P5
Burst Time
10
1
2
1
5
Priority
3
1
3
4
2
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5,
all at time 0.
a. Draw four Gantt charts illustrating the execution of these processes using FCFS,
SJF, a non-preemptive priority (a smaller priority number implies a higher
priority), and RR (quantum = 1) scheduling.
b. What is the turnaround time of each process for each of the scheduling algorithms
in part a?
c. What is the waiting time of each process for each of the scheduling algorithms in
part a?
d. Which of the schedules in part a results in the minimal average waiting time (over
all processes)?
7. This is an open question. Please write a 2 pages report on the past, present and future
of Operating System. Past means the history of operating system, such as how did
windows evolved? Present means the current ( year 2007 ) state of operating system.
Future means what operating system could be in 10 years from now. Do you best in
organizing the material you found online.
Reference:
Thread.c:
/**
* A pthread program illustrating how to
* create a simple thread and some of the pthread API
* This program implements the summation function where
* the summation operation is run as a separate thread.
*
* gcc thrd.c -lpthread
*
* Figure 4.6
*
* @author Gagne, Galvin, Silberschatz
* Operating System Concepts - Seventh Edition
* Copyright John Wiley & Sons - 2005.
*/
#include <pthread.h>
#include <stdio.h>
int sum; /* this data is shared by the thread(s) */
void *runner(void *param); /* the thread */
int main(int argc, char *argv[])
{
pthread_t tid; /* the thread identifier */
pthread_attr_t attr; /* set of attributes for the thread */
if (argc != 2) {
fprintf(stderr,"usage: a.out <integer value>\n");
/*exit(1);*/
return -1;
}
if (atoi(argv[1]) < 0) {
fprintf(stderr,"Argument %d must be non-negative\n",atoi(argv[1]));
/*exit(1);*/
return -1;
}
/* get the default attributes */
pthread_attr_init(&attr);
/* create the thread */
pthread_create(&tid,&attr,runner,argv[1]);
/* now wait for the thread to exit */
pthread_join(tid,NULL);
printf("sum = %d\n",sum);
}
/**
* The thread will begin control in this function
*/
void *runner(void *param)
{
int i, upper = atoi(param);
sum = 0;
if (upper > 0) {
for (i = 1; i <= upper; i++)
sum += i;
}
pthread_exit(0);
}
Download