程序代写案例-COMP 3430-Assignment 1

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 1/11
COMP 3430 - Operating Systems
Assignment 1
F
ranklin Bristow and Robert Guderian
Winter 2022
Description
Question 1: ELF
What to print
ELF Header
Program Headers
Section Headers
Running
Checking your output
32-bit binaries
Evaluation
Question 2: Herding Processes and Threads
Process herder
Thread herder
Notes
Evaluation
Submitting your assignment
General Advice
Description
In assignment 1, we are looking for you to be able to demonstrate a few different
things:
Reading and interpreting binary files (ELF).
Managing processes and communication with signals.
Managing threads and communication through shared memory.
Assignment 1 is due on Friday, February 18th, 2022 at 4:30pm CDT.
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 2/11
Submissions that violate any of the following will not be evaluated (i.e., you will
receive a score of 0 for the assignment):
All solutions must be written in C. No other languages are accepted.
All solutions must include a working Makefile.
Forget how to make a Makefile? Never knew how to make a Makefile?
Thankfully, you can go to https://makefiletutorial.com and find some
very easy to use basic examples.
Your Makefile should contain a clean rule. When
is run in your directory, all the temporary files, including the executable
should be removed (e.g., rm -f my_prog).
All solutions must be compiled by issuing the command make in the directory
containing the Makefile. No other build commands are acceptable, even if
documented in the README.md.
All solutions must include a Markdown-formatted README.md file that
minimally describes how to run your submission.
Forget how to make a README.md? Never knew how to make README.md?
Thankfully, you can go to https://readme.so/ and build a nice,
Markdown-formatted README.md with a nice preview and some handy
buttons to help you build it.
All solutions must run to successful completion. Premature termination for
any reason (no obvious output, Segmentation Fault, Bus Error, etc.) is
considered to be a solution implementation that does not run.
For programs that are expected to terminate on their own (without your
intervention), programs should complete in a reasonable amount of time
(e.g., < 30 seconds).
All solutions must compile. Code that does not compile will not be evaluated.
Programs must produce no errors when compiled with the flags
Note that -Werror prevents your code from being compiled when warnings
are present.
make clean
-Wall -Wpedantic -Wextra -Werror
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 3/11
If these flags are not in your Makefile, your submission will be treated as
though it does not compile.
Your code must compile and run on a machine on aviary.cs.umanitoba.ca.
No late submissions will be accepted. The assignment deadline is enforced
electronically. Submissions will not be accepted by e-mail.
Reminder: All submitted code will be evaluated using an automated similarity
testing tool, alongside commonly available online solutions for problems.
Question 1: ELF
Some ELFs don’t make toys, Public Domain
One of the first things than an operating system does when launching a new
process is to read the program into memory. Some operating systems (including
Linux) use ELF formatted binaries to represent compiled programs.
Using one of the two strategies for reading binary files described in the
supplementary video (and in lab 1), write a program that reads an ELF formatted
file and writes out some information about the program. Your program should
work for both 32-bit and 64-bit ELF files.
What to print
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 4/11
ELF Header
From the ELF header, your program should print out:
1. Whether the program is 32-bit or 64-bit.
2. The endianness of the file.
3. The target operating system ABI.
4. The object file type.
5. The instruction set architecture.
6. The address of the entry point from where the process starts executing.
7. The address of the program header table in the file.
8. The size of an entry and the number of entries in the program header table.
9. The size of an entry and the number of entries in the section header table.
10. The entry in the section headers that is the string table.
ELF header sample output
ELF header:
* 64-bit
* little endian
* compiled for 0x00 (operating system)
* has type 0x02
* compiled for 0x3e (isa)
* entry point address 0x00000000004010c0
* program header table starts at 0x0000000000000040
* there are 11 program headers, each is 56 bytes
* there are 33 section headers, each is 64 bytes
* the section header string table is 32
Note: This is sample output to show you the expected format. This doesn’t
necessarily show the actual outputs you will get (outputs will change based on the
file you’re reading).
Program Headers
For each program header, your program should print out:
1. The segment type.
2. The virtual address of the segment in memory.
3. The size in the file image of the program header.
4. The first (up to) 32 bytes of actual segment data, formatted as hexadecimal
bytes. Your output should be 16 bytes wide, and 16-bit byte pairs (i.e., 2 × 8
bits) should be printed as little-endian to match the output of hexdump.
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 5/11
Program header sample output
Program header #0:
* segment type 0x00000006
* virtual address of segment 0x0000000000400040
* size in file 616 bytes
* first up to 32 bytes starting at 0x0000000000000040:
06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00
40 00 40 00 00 00 00 00 40 00 40 00 00 00 00 00
Note: This is sample output to show you the expected format. This doesn’t
necessarily show the actual outputs you will get (outputs will change based on the
file you’re reading).
Section Headers
For each section header, your program should print out:
1. The name of the section.
The ELF header specifies which section header is the string table section
header (this is the last field in the ELF header). You can find the names
for sections in the file at the offset specified by the section header that is
the string table section.
2. The section header type.
3. The virtual address of the section in memory.
4. The size in the file image of the section header.
5. The first (up to) 32 bytes of actual section data, formatted as hexadecimal
bytes. Your output should be 16 bytes wide, and 16-bit byte pairs (i.e., 2 × 8
bits) should be printed as little-endian to match the output of hexdump.
Section header sample output
Section header #23
* section name .data
* type 0x01
* virtual address of section 0x0000000000400040
* size in file 617 bytes
* first up to 32 bytes starting at 0x0000000000000040:
06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00
40 00 40 00 00 00 00 00 40 00 40 00 00 00 00 00
Note: This is sample output to show you the expected format. This doesn’t
necessarily show the actual outputs you will get (outputs will change based on the
file you’re reading).
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 6/11
Running
Your program should accept the name of the ELF file it should read as its first
(and only) argument. Your program should be able to read itself. Here are some
examples of what you might want to check out:
Checking your output
Use the readelf command to help you check your output. The readelf command
will let you print out different parts of the file (different headers) by passing
different flags. To learn more about which flags print out which section, take a
look at man readelf.
To check that you’re printing the correct bytes for the different sections, you can
use a tool like hexdump along with the -s option. To learn more about how to use
hexdump, take a look at man hexdump.
32-bit binaries
You are able to compile 32-bit binaries using gcc and clang by passing the -m32
option:
Evaluation
5 points are awarded for code quality and design. “High quality” is defined as
code that follows the standards and best practices that you can find in the
“Standards and Best Practices” folder at the root of the Assignments section on
UM Learn:
Level Description

The code is very poor quality (e.g., no comments at all, no functions,
poor naming conventions for variables, etc).
./a1q1 a1q1
./a1q1 /usr/bin/cat
$ clang -m32 hello.c -o hello.out32 # compile the 32-bit binary
$ file hello.out32 # confirm that it's a 32-bit
binary
hello.out32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked, interpreter /lib/ld-linux.so.2,
BuildID[sha1]=409a97c495b0a9e9242a1e74a9901c17cab660ba, for
GNU/Linux 3.2.0, not stripped
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 7/11
Level Description

The code is low quality, while some coding standards are applied, their
use is inconsistent (e.g., inconsistent use of comments, some functions
but functions might do too much, code is repeated that should be in a
function, etc).
This is the maximum level you can earn if the implementation of your
program is substantially incomplete.

the code is high quality, coding standards are applied consistently
throughout the code base.
10 points are awarded for implementation (5 × 2):
Level Description
Submitted code does not run or compile.

Submitted code is substantially incomplete (e.g., only the ELF header
is read and produced as output).

Submitted code is substantially complete, but still incomplete (e.g., all
sections are present, but some are not correctly reproduced).
Submitted code is complete and accurate.
Question 2: Herding Processes and
Threads
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 8/11
Like herding sheep. (Public Domain)
Programs often have many workers doing some hard work in parallel. These
workers need to be controlled by a supervisor process or thread. Write two
programs that control how many worker threads or processes are currently
running - once using processes, once using threads.
Read a configuration file to decide how many worker processes or threads should
be used. Also, we want to be able to change the number of worker processes or
thread at run time. On receiving a SIGHUP, re-read the configuration file, and
change the number of current workers appropriately - creating or removing
processes or threads.
The “work” done in the workers can be a simple, empty while loop.
Process herder
For the process herder, use signals for communicating with your worker
processes. Use SIGINT to tell your workers to cleanly exit. The worker should
clean up any resources, and print a message saying that it got the signal and is
quitting.
The main process should quit on SIGINT, after cleaning any resources, and
waiting for all the child processes to exit.
Thread herder
For the thread herder you may choose any inter-thread communication you
choose. Worker threads must cleanly exit, cleaning up any resources before
exiting, printing a message stating that it is exiting.
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 9/11
Your supervisor thread should only exit after all the worker threads have exited.
Notes
You can do this part of the assignment using only the function calls (for
pthreads) and system calls (for processes) that you’ve seen in the textbook
(e.g., pthread_create and pthread_join; fork, wait, and kill).
You explicitly do not need to use any locks or condition variables for this
assignment (we’ll get to that later).
Think carefully about how threads and processes can communicate with each
other in terms of how you design the management of threads and processes
(as far as we know from week 3).
Evaluation
5 points are awarded for overall code quality and design for part 2. “High quality”
is defined as code that follows the standards and best practices that you can find
in the “Standards and Best Practices” folder at the root of the Assignments
section on UM Learn:
Level Description

The code is very poor quality (e.g., no comments at all, no functions,
poor naming conventions for variables, etc).

The code is low quality, while some coding standards are applied, their
use is inconsistent (e.g., inconsistent use of comments, some functions
but functions might do too much, code is repeated that should be in a
function, etc).
This is the maximum level you can earn if the implementation of your
program is substantially incomplete.

the code is high quality, coding standards are applied consistently
throughout the code base.
5 points for implementing each of threads and processes, for a total of 10 points.
Makefile must build both programs, and names of the files must clearly show
which program is which.
Level Description
Threads/processes are not started at all.
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 10/11
Level Description

Threads/processes are started, but no attempt is made to adjust the
number of running threads/processes at runtime.

Threads/processes are started and some reasonable attempt at
communication has been made, even if it doesn’t work in all cases.

Threads/processes are started, workers start and stop appropriately,
but the implementation is too complicated, difficult to understand, or
inappropriately uses functions outside the current scope of the course
(e.g., locks). Program flow is clearly visible from stdout.

Threads/processes are started, workers start and stop appropriately.
Appropriate design choices have been made. Program flow is clearly
visible from stdout. Supervisor and workers all completely clean up
before exiting.
Submitting your assignment
Submissions will be made using the handin command available on all CS UNIX
systems.
You should be submitting at least the following files:
A Makefile (you are permitted to have more than 1 Makefile, e.g., if you want
to have one Makefile per question).
A README.md that includes a summary of how to compile and run your
programs (compiling should be “run make”, but you should explicitly tell the
grader how to run your program, e.g., what arguments to pass to the program
on the command line).
Your solution for question 1 (probably just 1 .c file).
Your solution for question 2 (probably 2 .c files).
A complete assignment 1 folder might look something like:
[fbristow@cormorant ~]> tree my_a1/
my_a1/
|-- Makefile
|-- README.md
|-- a1-elf.c
|-- a1-procs.c
`-- a1-threads.c
0 directories, 5 files
2022/2/6 下午10:13 COMP 3430 - Operating Systems
file:///C:/Users/12042/Desktop/assignment.html 11/11
If your files are in a folder named my_a1, you would run the command:
handin will then make some happy noises to say that you’ve handed in your
folder successfully:
Note: the number of bytes that handin reports will always be smaller than the
size of your folder because handin compresses the folder before turning it in.
You can see man handin if you need more information.
General Advice
Here’s some general advice that you can choose to follow or ignore:
1. The debugger is your best friend. Don’t even start trying to solve these
problems until you’re comfortable with a debugger (either lldb or gdb). The
first question I’m going to ask when you come to ask me for help is: “Have
you tried running it through the debugger yet?” If you answer “no”, I’ll send
you away to do that first, then come back.
2. Source control is your second best friend. The department hosts an instance
of GitLab that you can use to store private projects. You’re also welcome to
use private repositories on GitHub.
handin 3430 a1 my_a1
[fbristow@cormorant ~]> handin 3430 a1 my_a1
handin: Time Stamp: Mon Jan 31 10:21:16 2022
Submitter: [email protected]
Total bytes copied to handin file was: 229
Handin was successful.

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: Fudaojun0228