Starting from:

$25

Operating Systems – Exercise 1 Solved

Part 1
In this question we will implement a C application that appends content from a file to another. The application should receive the buffer size (in bytes), source file path and target file path as command line arguments. By default, the application does not create a target file if such does not exist, unless the -f option was specified.

Read the manual page for the following System Calls i.e. execute: man 2 readREAD(2)
RENAME(2)
OPEN(2), and Carefully read about the following option flags:
                            O_RDONLY, O_WRONLY, O_CREAT,O_APPEND O_TRUNC, O_EXCL.

CLOSE(2)
Read the manual page for the following C Library CallsPERROR(3)
PRINTF(3)
EXIT(3)
Complete the application in the provided ex1.c file (missing parts are marked with //TODO).
 

Execution output e xamples: 

Output Requirements & Testin

In order to apply a uniform testing procedure to your submissions, your program must output one of the following types of messages (precisely and case-sensitive):

Unable to open source file for reading
Unable to open destination file for writing
Unable to append to destination file
Unable to append buffer content to destination file
Unable to read source file
Unable to close source file
Unable to close destination file
Content from file <source_file> was successfully appended to <destination file>
 

Or one of the various arguments parsing errors, as described in the examples above.

Note that all console outputs are expected to end with a newline as shown in the examples above.

Please notice that the output of your program will be checked, as well as the contents of the file that was created during the append process, if such append takes place.

Guidelines

Use the manuals. Chapters 2 & 3 are your friends
Make sure to always close the files you are using
Always check system calls return value for errors. ALWAYS.
You are not allowed to use any external / C-Library code that copies files, if you are not sure if you are allowed to use something, ask in the forum.
Your program must finish executing with EXIT_SUCCESS only when there were no errors (otherwise it must finish executing with EXIT_FAILURE after printing a helpful message).
Do not change function signatures, if provided.
Hint: the 4 system calls and 3 libc calls mentioned above are all you need to implement this part of the exercise successfully.
Using Docker for Smoke Testing
The VM is installed with Docker software (more on that later in the semester).
When being graded, your solution will be tested in a container identical to the one that will be built using the supplied Dockerfile.
There are two smoke tests (sanity checks) to this exercise. You can explore the
'EX1/check_submission/do_not_change' folder for more details o Test1 – tests a standard scenario: source file and destination file exist and not empty

Test2 - tests a scenario in which the destination file is missing (and there is no '-f' flag)
Usage:You’re given EX1 folder, containing:A ‘check_submission’ folder, which contains two tests (Test0, Test1) and a Python script to execute it (check_submission.pyc).
A skeleton file ‘ex1.c’ o Do not move ANY of the files inside check_submission, or you won’t be able to use our tests.
You should edit ‘ex1.c’ with your solution.
Each time you want to test your final submission file (zip file):
Open a terminal and go the EX1/check_submission.
copy your submission file (ex1-YOUR_ID.zip) to your machine (anywhere you want)
 

Execute 'python check_submission.pyc <full path to your submission file>'. for example:
 

If the two tests pass, you’ll get:
 

Part 2  
We will now examine the performance of our program from part 1.

Create a 5MB file using the following command:
dd if=/dev/zero of=/tmp/test.5mb bs=1M count=5

             

Run your program on this file, preceded with the time(1) command, using the following buffer sizes: 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200
$ time ./ex1 -f 51200 /tmp/test.5mb /tmp/test.5mb_dest File /tmp/test.5mb was copied to /tmp/test.5mb_dest

 

Real 0m0.004s 

User 0m0.000s

Sys 0m0.000s

            

Draw a graph (using Google Sheets or Microsoft Excel) with 3 series: Real, User, Sys. The series should show the time each run takes (in milliseconds) [Y axis], as a function of the buffer size [X axis]
Explain the graph:What is the meaning of Real, User and Sys (use Google)?
_____________________________________________________________________

_____________________________________________________________________ _____________________________________________________________________ ● Why don’t Sys and User sum up to Real?

_____________________________________________________________________

_____________________________________________________________________ _____________________________________________________________________

Why isn’t Real a straight line, parallel to the X axis?
___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

Hypothetically, if we change the append_file in part 1 to print out to the screen a message each time we read buffer_size bytes, will the running time change significantly?IMPORTANT: Do not make this change. Submission with this change will result in 0 points for this question!
              _______________________________________________________________________

             _______________________________________________________________________

              _______________________________________________________________________

Part 3 
Answer 'Homework 1 Quiz' in Moodle 

 

More products