Lab Assignment--System Calls for I/0


Lab Code

To get the sample and exercise code, please use the following commands in your cs330 directory:
   wget www.labs.cs.uregina.ca/330/SystemCall_IO/Lab7.zip
   unzip Lab7.zip
(Please do this lab on os1 or os2)

Exercise Description

The idea of this exercise is to communicate between a child and a parent using a shared file that the user will specify.

Your program will require the name of the file to be sent as a command line argument (argv[1])

A skeleton algorithm is provided below:

  1. Check that the number of command line arguments is 2. If it isn't, produce an error message. Note: you cannot use perror here.
     
  2. Use fork to produce a child and parent

  3. Don't forget to handle the error situation

Deliverables

Submit 2 files to URCourses

  1. Your Code
  2. Script containing the following commands (executable is called myIO):
    1. ls -l (Goal: show that no .txt files exist aside from your script file)
    2. ./myIO (Result: error message-not enough arguments)
    3. ./myIO file.txt (Result: no errors; gets input from the keyboard until you type CTRL-D; and creates file.txt with contents of what you typed)
    4. ls -l (Goal: show that file.txt has been created)
    5. cat file.txt (Goal: display the contents of the output file)
    6. ./myIO /file.txt (Result: two error messages - (1) permission denied on creating and (2) no such file when opening for reading- on file.txt in the root directory)

Notes