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 distributedsystems.

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 usingPthread thread library. This program shouldwork as follows: The user will enter on the command line the numberof Fibonacci numbers that the program is to generate. The program willthen create a separate thread that will generate the Fibonacci numbers,placing the sequence in data that is shared by the threads (an array isprobably the most convenient data structure).When the thread finishesexecution, the parent thread will output the sequence generated by thechild thread. Because the parent thread cannot begin outputting the Fibonaccisequence 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-bursttime given in milliseconds:

Process Burst Time Priority

Process / Burst Time / Priority
P1 / 10 / 3
P2 / 1 / 1
P3 / 2 / 3
P4 / 1 / 4
P5 / 5 / 2

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5,

all at time 0.

  1. Draw four Gantt charts illustrating the execution of these processesusing FCFS, SJF, a non-preemptive priority (a smaller prioritynumber implies a higher priority), and RR (quantum = 1)scheduling.
  2. What is the turnaround time of each process for each of thescheduling algorithms in part a?
  3. What is thewaiting time of each process for each of the schedulingalgorithms in part a?
  4. Which of the schedules in part a results in the minimal averagewaiting 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);

}