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:
-
Check that the number of command line arguments is 2. If it isn't, produce an error message. Note: you cannot use perror here.
-
Use fork to produce a child and parent
- Child will:
- open the file for writing (make sure to use the "create" flag
and permissions for the user to read and write)
- check for errors on opening and use perror to describe the error.
- read from standard input (until end of file,ie., you type CTRL-D)
- write to the file
- when done, close the file
- Parent will:
- wait for the child
- open the file for reading
- check for errors on opening and use perror to describe the error.
- write a message that you are in the parent
- read from the file (until end of file)
- write to standard output
- when done, close the file
Don't forget to handle the error situation
Deliverables
Submit 2 files to URCourses
- Your Code
- Script containing the following commands
(executable is called myIO):
- ls -l (Goal: show that no .txt files exist aside from your script file)
- ./myIO (Result: error message-not enough arguments)
- ./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)
- ls -l (Goal: show that file.txt has been
created)
- cat file.txt (Goal: display the contents of the output file)
- ./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
- Do not create a zip file
- Submission is on UR Courses
- Submit your own work
- Please properly indent your work. I will deduct marks for ziggy-zaggy code.
- Be mindful that your assignment is due two hours before the start of your next lab