Starting from:

$30

OperatingSystems–Exercise 1 Solved

Operating Systems – Exercise 1 


System Calls, Basic I/O 

Part 1 
In this question we will implement a C application that appends content from a file to another in reverse order. 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.

 

1.       Read the manual page for the following System Calls i.e. execute: man 2 read

a.      READ(2)

b.      LSEEK(2)

c.       WRITE(2)

d.      OPEN(2), and Carefully read about the following option flags:  

                            O_RDONLY, O_WRONLY, O_CREAT,O_APPEND, O_TRUNC, O_EXCL.

e.      CLOSE(2)

f.        FDOPEN(2)

2.       Read the manual page for the following C Library Calls

a.      PERROR(3)

b.      PRINTF(3)

c.       EXIT(3)

3.       Complete the application in the provided ex1.c file (missing parts are marked with //TODO).

 
Execution output examples:     


Output Requirements & Testing: 

 
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), using perror: 

●       Unable to open source file for reading

●       Unable to open destination file for writing

●       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 (in reverse) 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 note 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 system calls and libc calls mentioned above are all you need to implement this part of the exercise successfully.


Using Docker for Smoke Testing
●       When being graded, your solution will be tested in a container identical to the one that will be built using the supplied Dockerfile.

●       To use Docker, you first need to install it on your VM. Follow this guide.

●       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

o    Test2 - tests a scenario in which the source file is missing (and there is no '-f' flag) ● Usage:

o    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.py).

▪     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.

o    You should edit ‘ex1.c’ with your solution.

o    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.

Answer the following question in Moodle 'HW1 part2 Quiz'  

1.      Create a 5MB file using the following command:

dd if=/dev/zero of=/tmp/test.5mb bs=1M count=5 

              
2.      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 

              
3.      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]

4.      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?


5.      Hypothetically, if we change the append_file_reverse in part 1 to print out to the screen a message each time we read buffer_size bytes, will the running time change significantly?
        

Part 3 
Answer 'HW1 part 3 Quiz' in Moodle (10 T/F questions, 4 points each).

More products