Write a C/C++ program that performs the tasks described below. The program should fork one process. Have the new process execve the program named /bin/sed. Use dup2 (or dup) with a pipe to establish a way for the original process to capture stdout from sed. The program will accept command-line arguments that it passes along to sed via execve. Any valid sed arguments may be used during testing. Sample executions are given below. Be sure to have this: alarm(90); as the first executable line in *BOTH* processes, which means you will need to do it in at least one of the processes after the fork.
Write a C/C++
The program should fork one process. Have the new process execve the
program named /bin/sed. Use dup2 (or dup) with a pipe to establish a way
for the original process to capture stdout from sed. The program will
accept command-line arguments that it passes along to sed via execve.
Any valid sed arguments may be used during testing.
Sample executions are given below.
Be sure to have this:
alarm(90);
as the first executable line in *BOTH* processes, which means you will
need to do it in at least one of the processes after the fork.
Tests will be done by typing commands like this:
./p4 's/p/Z/g' TEMPIN
The original process should capture stdout from sed and then print EACH line
prefixed by:
SED:
For correctness, it is important that EACH line have the prefix.
For example, suppose that TEMPIN contains these lines:
harry potter powerful wizard
hermione played chess
snape taught many pupils
If the program is run as above:
./p4 's/p/Z/g' TEMPIN
then it would print:
SED: harry Zotter Zowerful wizard
SED: hermione Zlayed chess
SED: snaZe taught many ZuZils
Trending now
This is a popular solution!
Step by step
Solved in 2 steps