Presentation is loading. Please wait.

Presentation is loading. Please wait.

OS Assignment 3.

Similar presentations


Presentation on theme: "OS Assignment 3."— Presentation transcript:

1 OS Assignment 3

2 Assignment3 Requirements
30% in the total grade Nachos: Four code writing jobs Linux: Two code writing jobs Choose one of them

3 NachOS assignment Multiprogramming
You have to write a scheduling program of RR (Round Robin). Round-robin (RR) is one of the scheduling algorithms for processes in an operating system, which assigns time slices to each process in equal portions and in circular order, handling all processes without priority. You have to print the progress of several processes, and show your time slice.

4 NachOS assignment Thread
You have to implement a Unix-like instruction ps (process status). The ps utility displays a header line, followed by lines containing information about all of your processes that have controlling terminals. You have to show USER, PID, TIME (excusing time) and COMMAND at least.

5 NachOS assignment Memory
You have to implement a Unix-like instruction top. The top provides an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system, and can provide an interactive interface for manipulating processes. The top utility display and update information about the top cpu processes. You have to show USER, PID, SIZE (memory), CPU time used and COMMAND at least. And it’s ranking by CPU time used.

6 NachOS assignment File system
You have to implement a Unix-like instruction ls –l (list directory contents). Please not only list directory contents, but also show USER (who create), SIZE, TIME (create time) and NAME (directory name or file name) at least.

7 Linux assignment Part I
You must write a game about the racing of turtles and rabbits. Your assignment should include several processes, which represent the turtles and the rabbits, and one process prints the progress of the turtles and rabbits and handles signal Turtle (⊕) rabbit ( ¥ )

8 Game rules Rabbit walks five paces per second
Turtle walks two paces per second User press ctrl+z to generate a random event and the even must elapse five seconds Print the status of the racing on the screen per second The winner is the first arriving sixty paces

9 Some event types Increasing the speed of the rabbit
1/10 probability Rise from five to eight paces per second Increasing the speed of the turtle 2/5 probability Rise from two to five paces per second Stop the rabbit 1/5 probability Wake the rabbit up Decreasing the speed of the turtle Change from two to one paces per second Change from five to two paces per second

10 Result Example EX: -------------------------------------------- ¥ r1
rabbit1 24 paces rabbit2 50 paces turtle1 42 paces

11 Requirements After compiling, the final program must be named “hw3_race” You are responsible for writing a makefile suitable for your whole program Usage example ./hw3_race 2 3 Create two rabbits and three turtles

12 Linux assignment Part II
You must implement an odd-and-even sort algorithm to sort 10 integers. Handle odd-and-even sort with some semaphores to handle odd processes and even processes You must print the status of each step of sorting on the screens Please use semaphore to control your sort!

13 Odd-And-Even Sort It is a comparison sort based on bubble sort with which it shares many characteristics. It functions by comparing all (odd, even)-indexed pairs of adjacent elements in the list and, if a pair is in the wrong order (the first is larger than the second) the elements are switched. The next step repeats this for (even, odd)-indexed pairs (of adjacent elements). Then it alternates between (odd, even) and (even, odd) steps until the list is sorted. It can be thought of as using parallel processors, each using bubble sort but starting at different points in the list (all odd indices for the first step). -- [Wikipedia]

14 hw3_sort 1 hw3_sort2 hw3_sort 3 hw3_sort 4 hw3_sort 5 3 6 4 2 1 5 10 9 7 8 2 3 1 6 4 5 9 10 7 8 2 1 3 4 6 5 9 7 10 8 1 2 3 4 5 6 7 9 8 10 … etc

15 Semaphore Needed header files Needed functions <sys/ipc.h>
<sys/shm.h> (share memory relateded) <sys/sem.h> <sys/types.h> Needed functions int semget(key_t key,int nsems,int semflg); int semctl(int semid,int semnum,int cmd,union semun arg);  int semop(int semid,struct sembuf *spos,int nspos);

16 Semaphore Functions int semget(key_t key , int nsems , int semflg); semid = semget(SHMKEY, 1 , 0777|IPC_CREAT); int semctl(int semid,int semnum,int cmd,union semun arg);  semctl(semid, 0, SETVAL, 1) int semop(int semid,struct sembuf *spos,int nspos); semop(semid, &buf, 1)

17 Part II Requirements After compiling, the final program must be named “hw3_sort” You are responsible for writing a makefile suitable for your whole program Use five screens to show your homeworks Start screen: screen Create screen: ctrl + a+ c Switch to next screen: ctrl + a + n Switch to previous screen: ctrl + a+ p Please close your screens after finishing your jobs exit exit exit exit… Usage examples ./hw3_sort (input 10 numbers) ./hw3_sort 1 (the first windows…etc) ./hw3_sort 2 (the second windows…etc) …etc

18 linux ~/ $ ./hw3_sort Please enter 10 intergers num1:3 num2:2 num3:1 num4:6 num5:5 num6:4 num7:10 num8:9 num9:7 num10:8 enter 10 numbers finish. waiting for the child process... Sorted value0 = 1 value1 = 2 value2 = 3 value3 = 4 value4 = 5 value5 = 6 value6 = 7 value7 = 8 value8 = 9 value9 = 10

19 linux ~/ $ ./hw3_sort 1 not sorted: addr1[0] = 3 ,addr1[1] = 2 sorted : addr1[0] = 2 ,addr1[1] = 3 not sorted: addr1[1] = 3 ,addr1[2] = 1 sorted : addr1[1] = 1 ,addr1[2] = 3 not sorted: addr1[0] = 2 ,addr1[1] = 1 sorted : addr1[0] = 1 ,addr1[1] = 2 not sorted: addr1[1] = 2 ,addr1[2] = 3 sorted : addr1[1] = 2 ,addr1[2] = 3 not sorted: addr1[0] = 1 ,addr1[1] = 2

20 linux ~/ $ ./hw3_sort 2 not sorted: addr1[2] = 1 ,addr1[3] = 6 sorted : addr1[2] = 1 ,addr1[3] = 6 not sorted: addr1[3] = 6 ,addr1[4] = 4 sorted : addr1[3] = 4 ,addr1[4] = 6 not sorted: addr1[2] = 3 ,addr1[3] = 4 sorted : addr1[2] = 3 ,addr1[3] = 4 not sorted: addr1[3] = 4 ,addr1[4] = 5 sorted : addr1[3] = 4 ,addr1[4] = 5

21 linux ~/ $ ./hw3_sort 3 not sorted: addr1[4] = 5 ,addr1[5] = 4 sorted : addr1[4] = 4 ,addr1[5] = 5 not sorted: addr1[5] = 5 ,addr1[6] = 9 sorted : addr1[5] = 5 ,addr1[6] = 9 not sorted: addr1[4] = 6 ,addr1[5] = 5 sorted : addr1[4] = 5 ,addr1[5] = 6 not sorted: addr1[5] = 6 ,addr1[6] = 7 sorted : addr1[5] = 6 ,addr1[6] = 7 not sorted: addr1[4] = 5 ,addr1[5] = 6

22 linux ~/ $ ./hw3_sort 4 not sorted: addr1[6] = 10 ,addr1[7] = 9 sorted : addr1[6] = 9 ,addr1[7] = 10 not sorted: addr1[7] = 10 ,addr1[8] = 7 sorted : addr1[7] = 7 ,addr1[8] = 10 not sorted: addr1[6] = 9 ,addr1[7] = 7 sorted : addr1[6] = 7 ,addr1[7] = 9 not sorted: addr1[7] = 9 ,addr1[8] = 8 sorted : addr1[7] = 8 ,addr1[8] = 9 not sorted: addr1[6] = 7 ,addr1[7] = 8 sorted : addr1[6] = 7 ,addr1[7] = 8 not sorted: addr1[7] = 8 ,addr1[8] = 9

23 linux ~/ $ ./hw3_sort 5 not sorted: addr1[8] = 7 ,addr1[9] = 8 sorted : addr1[8] = 7 ,addr1[9] = 8 not sorted: addr1[8] = 10 ,addr1[9] = 8 sorted : addr1[8] = 8 ,addr1[9] = 10 not sorted: addr1[8] = 9 ,addr1[9] = 10 sorted : addr1[8] = 9 ,addr1[9] = 10

24 Assignment3 Requirements
Please do your homework on the work station ( ) If you insist doing your homework on your own computer, please make sure your homework can run at the workstation Upload your web pages(introduction) to FTP (ftp:// /homework3) If you do your homework on your own computer, please also upload your source code to FTP too. Due Date : 2009/6/2 11:59 p.m.


Download ppt "OS Assignment 3."

Similar presentations


Ads by Google