Write a program that receives one command-line argument: the name
of a text file. Your program will work as follows:
Start out by creating a child process.
The child process calls exec to run cat command with command-line argument that
the parent received.
The parent process calls wait so that it blocks until the child terminates and passes
back its termination status.
If the child process terminates without error, the parent spawns another child and,
again, calls wait so that it can block until the child terminates.
The new child calls exec again, but this it runs wc command on the same
the argument that the parent received from the command line.
Once the parent learns that the child has been terminated, it goes on to terminate also. If
the parent gets to this point, it’s because all has gone well.
class File
{
public:
File(string filename)
{
try
{
cout << "File" << filename << "open" << endl;
}
catch (exception exp)
{
cout << "Error! " << exp.what() << endl;
}
}
private:
string filename;
};
int main()
{
string filename;
cin >> filename;
File f(filename);
}
Comments
Leave a comment