Question

1. Create a file called openClose.in. You may cut and paste content from the lab notes into this file.

2. Write a C++ program 'openClose.cpp' that copies openClose.in to a file called openClose.out. Use open(), read(), write() and close() system calls. Use a buffer size of 32 bytes for reads and writes.
A call to your program will look something like this:
openClose openClose.in openClose.out
If you have the wrong number of arguments, your code will produce a message like the following:
%openClose
Usage: openClose <inFile> <outFile>
Check for errors and use perror. For instance, you should see something like the following if the user types an nonexistent input file:
%openClose noSuchFile openClose.out

inFile is noSuchFile fd = -1         errno = 2
InFile Error: No such file or directory
      
3. Call fstat() in the openClose.cpp program and print the following information about openClose.out: the file size (in bytes), the owner and group IDs, and the time it was last modified. The output can be in the following format:
This is the status of openClose.out
File Size      Owner       Group ID    Last Modified
815             10064          200             1097124530
If you want to do more, you can output in the following format:
This is the status of openClose.out
File Size      Owner       Group ID    Last Modified
815               nova          csfac          Wed Oct 6 22:48:50 2004
To do this, you can make use of library calls: getgrgid, getpwuid, and ctime. Check out the man pages for these calls.
You do not have to use the write system call for this last step. If you want, you can use printf to format your output nicely.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#!/bin/bash

echo Goal: show that openClose.out does not exist
ls -l
echo Goal: display the contents of the input file
cat openClose.in
echo Result: error message-not enough arguments
./openClose
echo Result: error message-not enough arguments
./openClose openClose.in
echo Result: error message-no such file
./openClose noSuchFile openClose.out
echo Result: no errors runs to completion and creates openClose.out
./openClose openClose.in openClose.out
echo Goal: show that openClose.out has been created
ls -l
echo Goal: display the contents of the output file
cat openClose.out
echo Result: error message-permission denied on creating openClose.out
./openClose openClose.in /openClose.out...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Computer Science Problems
Homework Solution
$30.00
Computer Science
Linux
C Programming Language
Kernel Source Tree
Systems
Numbers
Architecture
Integers
Input
Output
Strace Utility
Basic Commands
Algorithms
File Management
Compilers
Computer Science Questions
Homework Solution
$75.00
Computer Science
Linux
Memory
CPU
Algorithms
Jobs
Percentage
Deadlock
Programmers
PCS Scheduling
SCS Scheduling
Resources
Vectors
Tasks
System Snapshots
Logical Addresses
Physical Addresses
Transfers
VI Editor Exercises
Homework Solution
$25.00
Vi
Editor
Edit
File
Copy
Paste
Home
Directory
Screenshot
Output
Insert
Save
Computer
Science
Linux
Shell
Scripting
Get help from a qualified tutor
Live Chats