首页 » 操作系统辅导 » 操作系统代写 | Operating Systems (COMP2006) Semester 1, 2020

操作系统代写 | Operating Systems (COMP2006) Semester 1, 2020

这个作业是用进程间的通信等模拟一个电梯系统
Operating Systems (COMP2006) Semester 1, 2020
CURTIN UNIVERSITY
School of Electrical Engineering, Computing and Mathematical Sciences
Discipline of Computing
Assignment
Lift-simulator
Due Date: 4.00 p.m. Monday 11th May, 2020
The objective of this programming assignment is to give you experiences in using multiple
processes and multiple threads and their inter process / thread communications. You will
learn how to create processes and threads and solve some critical section problems. The
programs for this Lift-simulator should include the following features.
1. There are three elevators, Lift-1, Lift-2, and Lift-3, which are servicing a 20-floor
building (Floors 1 to 20). Assume that initially all lifts are in Floor 1. Each lift waits for
lift requests from any floor (1 to 20) and serves one request at a time.
2. Create a file sim_input to store n requests in the following formats, for n between 50
and 100.
1 5
7 2
3 8
4 11
.
.
.
12 19
20 7
The first number in each request represents the floor where the request is made, and the
second number is the destination floor. The two numbers are separated by a space. For
example, the first request comes from Floor 1 to go up to Floor 5, while the last request
is from Floor 20 to go down to Floor 7.
3. Create a task Lift-R that runs a function request() to get one lift request at a time from
sim_input, and puts the request into a buffer of size m ≥ 1. Thus there are at most m
pending lift requests. The function puts a request to the buffer when there is available
space. Otherwise, Lift-R is blocked waiting for available space in the buffer.
4. Create three tasks to simulate Lift-1, Lift-2, and Lift-3, each of which runs a function
lift() to perform operations of each lift. For each request, Lift-1, Lift-2, or Lift-3
removes the request from buffer, goes to the floor where the request is made, and
moves to the destination floor. Then the lift waits for the next available request if buffer
Operating Systems (COMP2006) Semester 1, 2020
2
is empty, or grabs another request from buffer. Since lifts need time to go from one
floor to others, you should simulate this event; this can be done, for example, by using
sleep(t) if the time needed is t seconds. To simplify, our simulator assumes each lift
requires the same time, t seconds, for each request, for t  0. For example, the time to
go from Floor 3 to Floor 5 (2 floor-distance), is the same as the time for the lift to go
from Floor 9 to Floor 4 (5 floor-distance).
5. Consider accessing buffer as the bounded buffer producer-consumer problem, where
Lift-R is the producer and Lift-1, Lift-2, and Lift-3 are the consumers.
6. Create a file sim_out to record all activities of Lift-1, Lift-2, Lift-3, and Lift-R. When
Lift-1 that is located in Floor 8, for example, has completed a request from Floor 2 to go
to Floor 9, Lift-1 records its activity in sim_out as:
Lift-1 Operation
Previous position: Floor 8
Request: Floor 2 to Floor 9
Detail operations:
Go from Floor 8 to Floor 2
Go from Floor 2 to Floor 9
#movement for this request: 13
#request: 5
Total #movement: 70
Current position: Floor 9
Note that the “#movement” is from the lift’s previous position to the floor from which
the request is made to the destination floor of the request; for the example we have (8 –
2) + (9 – 2) = 13. The “#request” is the total number of requests that Lift-1 has served,
while “Total #movement” is the total number of movements to serve those requests.
Each lift keeps these two values in two variables.
Similarly, each time a request is added into buffer, Lift-R prints the following
information in sim_out.
——————————————–
New Lift Request From Floor 8 to Floor 2
Request No: 21
——————————————–
The “Request No” is the number of requests that Lift-R has put into buffer.
7. File sim_out is shareable among Lift-1, Lift-2, Lift-3 and Lift-R; therefore, accessing
the file needs proper mutual-exclusion.
8. Your simulator terminates when all requests in sim_input have been put into buffer. The
simulator then computes the total number of requests (the sum of #request of all lifts),
and the total number of movements (the sum of Total #movement of all lifts). It then
prints the results in sim_out:
Operating Systems (COMP2006) Semester 1, 2020
3
Total number of requests: 100
Total number of movements: 5520
9. As part of your program, you have to remove all tasks that have been created to avoid
zombies, all other resources, and close all open files.
Part A: Implementation using pthreads (50%)
As threads by default share memory, for this part you need not create shared memory, e.g., for
buffer. However, you must address all necessary synchronization issues. Among others, use
pthread_mutex_lock(), pthread_mutex_unlock(), pthread_cond_wait(),
pthread_cond_signal(), and pthread_join() in your program.
To test your program, you should run the program as follows:
lift_sim_A m t
Thus, you have to name you executable file lift_sim_A; m is the buffer size, and t is the time
required by each lift to serve a request.
Part B: Implementation using processes (30%)
Since processes do not share memory, the parent process needs to create shared memory, e.g.,
for buffer. You must also address all necessary synchronization issues. You can use either
POSIX or System V for semaphores and shared memory. Make sure that the parent process
waits for the termination of all child processes and remove the shared memory, and
semaphores.
To test your program, you should run the program as follows:
lift_sim_B m t
Thus, you have to name you executable file lift_sim_B; m is the buffer size, and t is the time
required by each lift to serve a request.
Operating Systems (COMP2006) Semester 1, 2020
4
Instruction for submission
1. Assignment submission is compulsory. Students will be penalized by a deduction of ten
percent per calendar day for a late submission. An assessment more than seven
calendar days overdue will not be marked and will receive a mark of 0.
2. You must (i) submit the soft copy of the report to the unit Blackboard (in one zip file),
and (ii) put your program files i.e., lift_sim_A.c, lift_sim_B.c, makefile, and other files,
e.g., sim_input and sim_out, in your home directory named OS/assignment.
3. Your assignment report should include:
 A signed cover page that explicitly states the submitted assignment is your own work.
The cover includes the words “Operating Systems Assignment”, and your name in the
form: family, other names. Your name should be as recorded in the student database.
 Software solution of your assignment that includes (i) all source code for the
programs with proper in-line and header documentation. Use proper indentation so
that your code can be easily read. Make sure that you use meaningful variable names,
and delete all unnecessary comments that you created while debugging your program;
and (ii) readme file that, among others, explains how to compile your program and
how to run the program.
 Detailed discussion on how any mutual exclusion is achieved and what processes /
threads access the shared resources.
 Description of any cases for which your program is not working correctly or how you
test your program that make you believe it works perfectly.
 Sample inputs and outputs from your running programs.
Your report will be assessed (worth 20% of the overall assignment mark).
Failure to meet these requirements may result in the assignment not being marked.


程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持 Alipay WeChatPay PayPal等支付方式

E-mail: vipdue@outlook.com  微信号:vipnxx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论

您的电子邮箱地址不会被公开。