UCCD 2103 OPERATING SYSTEMS

代写UCCD 2103作业、代做Linux OS留学生作业、代做CS/O课程设计作业、代写CS/OS编程作业
OPERATING SYSTEMS
UCCD 2103
OCT 2018
ASSIGNMENT REPORT
Part A / Part B
No. Student ID Name Course
1
2
3
V1.1
2
Assignment
Guideline:
This assignment is a group assessment. Each group (max. 3 students per group) has to
practice the following and submit the hardcopy reports. There is no restriction of forming a
group out of your tutorial group. Maximum marks for this assignment is 130. It has two
parts: Part A and Part B. Both parts use the Linux OS. Running a virtualized Linux
(Virtualbox or VMWare Player) is also acceptable. You can use either 32-bit or 64-bit Linux,
depending on your host OS if you use virtualization. To limit uncertainties and possible
issues you might run into, you are recommended (but not limited) to use Fedora or CentOS
for this assignment. Make sure you allocate at least 25GB for your Linux partition. The
username of your Linux system must be set to your first name. For example, the username of
my system is cheesiang. Your report shall contain all group member’s names and IDs, and
your group leader’s email address. Also, write down the specification of the system that you
use to perform this assignment for both Part A and Part B, respectively. Your report should
provide the screenshots of the terminal to support all your answers. If the screenshot size is
too big and resulting to a very small font size in your printout, you may resize your desktop
resolution to 800x600 before taking the screenshot. If the screenshot is still too large (or the
font is too small), you may crop it; as long as you can proof the originality of your work.
For example, for command lines-based question, you should not crop out your user name as it
is used to identify your group’s work. Any group reports that have the same screenshots or
usernames will be counted as plagiarism and be given 0 marks. The hardcopies of report and
source codes shall be printed in black and white colour, double sided, and without comb
binding to minimize cost. Also, please upload the softcopy of your answers (report and
source codes) in a compressed file to the WBLE. Use the following naming format:
[yourgroupleadername]. The compressed file shall have the following:
Folder: Part A source codes
o Q2.c
Folder: Part B source codes
o Q1a.sh
o minus.sh
o monitor1.sh
o monitor2.sh
o create_user.sh
o remove_user.sh
PDF file: Report.pdf
Text file: Group_members.txt (Group members list)
Only the group leader needs to upload them. Please cite all the references you use. The due
date is 27
th of November, 2018, 5PM.
V1.1
3
Part A: Concurrency
1. Concurrency issues: mutual exclusion and race condition
Figure 1
a) This question is about mutual exclusion. It requires the following packages to
be installed as root before you can attempt it:
i. gcc C language compiler will be used. Command: yum install gcc
ii. pthread library to be installed. pthread is a POSIX Linux KLT
threading library. Command: yum install glibc-devel to install.
b) Switch back to your own user login. Download race.c source code from the
WBLE.
To compile it, enter: gcc race.c -lpthread -lrt -o race
To run it, enter: ./race
The program will create two concurrent threads to simulate traffics flowing
10s from opposing sides using a bridge (critical section), as shown in Figure 1.
Figure 1 illustrates a bridge across a river. Only vehicles from one direction
can cross the river at a time. Thus, vehicles from north and south need to take
turn to cross the river. Traffics from north and south are simulated by thread
t1 and t2 respectively. Both threads perform the same thing: (1) Identify
their own thread number, and (2) enter the critical section which is a bridge.
Study the source codes and answer the following question:
Has the mutual exclusion been properly implemented in the race program?
Provide your justification to support your finding. You may use screenshot of
your program output to assist your explanation. (10 marks)
c) Download sem.c source code from the WBLE. The program will enforce
mutual exclusion onto the program in Q1b) by using semaphore. Compile and
run it. Both threads perform the same thing: (1) Identify their own thread
V1.1
4
number, (2) Issue semWait before entering the critical section, and (3) Issue
semSignal after leaving the critical section. Study the source codes and
answer the following question:
Has mutual exclusion been properly implemented in the program? Provide
your justification to support your finding. You may use screenshot of your
program output to assist your explanation. (10 marks)
d) Does race condition occur in the sem.c? If yes, provide your justification.
You may explain by showing how the program works by providing
screenshot. (10 marks)
2. Semaphore
We improved the solution in Figure 1 by adding two traffic lights: Traffic light 1
and 2 to control traffic from North and South respectively, as shown in Figure 2.
Each traffic light will stay green for 10 seconds.
Figure 2
The problem can be simulated by using two threads. Assume that
thread t1 simulates the traffic from north.
thread t2 simulates the traffic from south.
initially, traffic light 1 is green.
semaphore 1_green indicates the traffic light 1 is green whereas
semaphore 2_green indicates the traffic light 2 is green.
Write the code for the two threads which are synchronised by using semaphores.
You may modify from the sem.c code. Make both threads to run continuously
by adding an infinite while loop. Test the correctness by running your solution
multiple times. It should eliminate race condition. (20 marks)
Hint: You may use the variable *t_number to control t1 and t2 logic.
V1.1
5
Part B: Linux Administration
1. Bash
a. A shell script is a sequence of shell commands written in an executable script
file. Executing this file instructs the shell to execute all commands in the order
of their appearance in the script file. There exist several shell scripting
tutorials available on the web, e.g. search by entering the keywords Linux
shell script tutorials. Go through one of these tutorials and then write a shell
script that displays the following system parameters:
i. Your user’s name
ii. The kernel version of your Linux OS
iii. The number of cores in your processor
iv. The current directory of the terminal
v. Date of the system
vi. The local IP address of your system
vii. The total memory and free memory the system has
viii. The uptime elapsed in your system at the time you run the script
You need to include the script and also screenshot of the results after the script
is executed in your hardcopy report. Please include the shell script codes into
softcopy disc as well. (8 marks)
b. Write a simple bash shell script that performs deduction of two integer inputs
via two input arguments. E.g. when your run the script: ./minus.sh 2 8 it
will output -6. (4 marks)
c. ps is a command that displays information about all processes currently
running in your system. Read man page of ps command (type man ps).
Enter the following commands: (1) ps –ef | more and (2) ps –aux |
more. Both of these will result in displaying a long list of processes. This
question will guide you how to design a simple resource monitoring tool using
Bash scripting, specifically monitor all Morzilla Firefox and
LibreOffice tasks’ CPU% or memory% consumption. Open two
browsing tabs in your Morzilla firefox and LibreOffice Calc.
Then, answer the following questions:
i. Write the command to identify what tasks (means process and threads
in Linux) are started by your username. (2 marks)
ii. Write the command to retrieve the following information. For each
task, find out who owns it, what code (the task name) it is running, and
how much processor (%CPU) and memory (%Mem) resources have
been used by them. Then, output these information into a file called
tasks.log. (8 marks)
iii. Write the command to read tasks.log and filter it so that it only
shows the Morzilla firefox and LibreOffice tasks’ %CPU.
Sum all them up and output the summation into a file called
monitor.log. (8 marks)
iv. To make your monitoring tool to be able to monitor the firefox and
LibreOffice CPU consumption periodically, compile your answer
from i to iii to form a shell script called monitor1.sh. The shell
script must be able to let the user to determine the period (how
frequent) of monitoring the %CPU reading by using the first input
V1.1
6
argument. For example, if the user intends to monitor the firefox
and LibreOffice CPU consumption every 2 seconds, the command
shall be: ./monitor1.sh 2 (10 marks)
v. There is still room for improvement. We shall allow the user to
specifically choose whether to monitor the firefox or
LibreOffice CPU consumption and save the log file into
firefox.log or libre.log, depending on what the user chose.
Improve the shell script in iv and save it as monitor2.sh. The script
can let the user to choose which program to be filtered by using the
second argument. For example, executing ./monitor2.sh 5
firefox will monitor the CPU consumption of firefox every 5
seconds and output it to firefox.log. (10 marks)
2. Administration and Files
Create a script file named “create_user.sh” that helps the administrator to
add new user to the system, without password and other information (a noninteractive
process). The new username will be passed to the script as the
argument (i.e. to create user cheesiang it, enter ./create_user.sh
cheesiang). Actions to be performed after the creation of user:
Create two directories in the new user’s home directory, namely “manual”
and “backup”.
Copy a file named “readme.txt” from current directory to the new user’s
manual directory, assume that “readme.txt” always exists in the current
directory.
Change the ownership appropriately so that the new user owns the files.
List the complete command so that the new user can only read their own
readme.txt but is not able to edit it. Other users from other groups cannot
access the file at all. (20 marks)
3. Administration and Files
Create a script file named “remove_user.sh” that helps administrator to
remove a user from the system and subsequently remove the user’s home
directory from the system as well. Username is passed to the script as the
argument. (10 marks)
References:
Linux Shell Scripting Tutorial v1.05r3: A Beginner's handbook. 2018. [ONLINE]
http://www.freeos.com/guides/lsst/ . [Accessed 01 November 2018].
How to use POSIX semaphores in C language2018. [ONLINE]
https://www.geeksforgeeks.org/use-posix-semaphores-c/. [Accessed 01 November
2018].

http://www.daixie0.com/contents/14/2144.html

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/welcomejava/p/10046347.html