Operating Systems Exercise 1-System Calls, Basic I/O Solved

30.00 $

Description

Rate this product
  1. Part 1In 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.
    1. Read the manual page for the following System Calls i.e. execute: man 2 read
      1. READ(2)
      2. RENAME(2)
      3. OPEN(2), and Carefully read about the following option flags:O_RDONLY, O_WRONLY, O_CREAT,O_APPEND O_TRUNC, O_EXCL.
      4. CLOSE(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:

$ ./ex1

Invalid number of arguments Usage:

ex1 [-f] BUFFER_SIZE SOURCE DEST

$ ./ex1 /etc/passwd /tmp/passwd

Invalid number of arguments Usage:

ex1 [-f] BUFFER_SIZE SOURCE DEST

$ ./ex1 4096 /etc/passwd /tmp/passwd

Unable to open destination file for writing: No such file or directory

$ ./ex1 -f 4096 /etc/passwd /tmp/passwd

Content from file /etc/passwd was successfully appended to /tmp/passwd

$ ./ex1 -f 4096 /tmp/passwd /etc/passwd

Unable to open destination file for writing: Permission denied

$ ./ex1 4096 /etc/password /tmp/passwd

Unable to open source file for reading: No such file or directory

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):

• • • • • • • •

Or one

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>

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 arenot 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 toimplement 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 thatwill 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
o Test2 – tests a scenario in which the destination 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) anda 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.

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 (anywhereyou want)

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

▪ If the two tests pass, you’ll get:

Part 2 (24 points)

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

  1. Create a 5MB file using the following command:
  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
  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 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!

      _______________________________________________________________________
      _______________________________________________________________________
      _______________________________________________________________________

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

$ 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

Part 3 (40 points)

Answer ‘Homework 1 Quiz’ in Moodle (10 T/F questions, 4 points each).

  • Ex1-4ihwox.zip