辅导OS python程序、辅导辅导OS、辅导OS报告
- 首页 >> OS编程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.