联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> OS作业OS作业

日期:2018-06-11 03:21


CSE 304 - Operating Systems

DUE: June 11. Submit in class

Programming Assignment (version 2)

From this assignment, you will learn the basic concept of synchronization (e.g., critical

section).

You will create a program creating/handling multiple processes. Each process is to sort

an integer list in an increasing order. The list is a shared variable (global) among all

processes; it is initialized randomly with [0-99] at the beginning of thread in process. The

list size is 10 (insert integer at most 10 times, then sort). After initialization, the process

will sort the array without any interrupt. At the end, you will release the list for other

processes to use. You should use a semaphore to synchronize between the threads.

A. The size of list is 10.

B. The number of processes is 10.

C. Your output should include each sorted list (in a single line).

D. Your output should report the start/end time of each process. You can calculate

the execution time, perhaps using the python module like ‘timeit’

(https://docs.python.org/2/library/timeit.html).

Task 1. Create 10 sorting processes, run them, and print output like the example below.

Your output may be incorrect, not sorted correctly (meaning that there is no

synchronization among the processes). Please refer to

https://pymotw.com/2/multiprocessing/basics.html for multiprocessing module. The

filename should be ‘sort_process_task1.py’

Task 2. Using multiprocessing.lock() function (it’s equivalent to semaphore) to control

access to critical section. You allow only one process at a time. The final output should

have all 10 lists correctly sorted. The filename should be ‘sort_process_task2.py’

EXAMPLE:

>> ./sort_process_task2.py

##### Process #1 started …

##### Process #2 started …

[1]--> 0 1 2 3 4 5 6 7 8 9 0.007 sec

[2] --> 10 11 12 13 14 15 16 17 18 19 0.006 sec

SUBMISSION:

1. Print out your source code for both tasks: sort_process_task1.py &

sort_process_task2.py

2. Print out the output of your programs (task1 & task2 separately).

3. Write one paragraph explaining your development environment, your program,

and any difficulties you had (no less than 200 words).

NOTE:

1. Python is required.

2. Any platform of your choice is fine, but I’d like to see many Linux (e.g., Ubuntu)

as possible. Use your Virtualbox.

3. Take a good look at the multiprocessing module example. It’s all there.

TRIVIA:

Google is your friend and teacher. Search!

Discuss with your classmates! (DO NOT send me an email first)

I will go over the assignment in class, so don’t worry too much.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp