Question: Q 4 . Write a program in C to simulate the output redirection using the dup family of system calls ( dup , dup 2

Q4. Write a program in C to simulate the output redirection using the dup family of system calls(dup, dup2, dup3).
[20 points]
This program consists of 2 parts :
Part 1: Simple Output Redirection
- Implement a function
- That opens a file for writing (From user)
- Uses dup / dup2 to redirect stdout to file
- Prints some random text to the redirected stdout
- Verify that the data is written in the file.
./q4-p1 output_p1.txt // output.txt must contain some random text
Part 2: Interactive Simulation
- Simulate a simple shell-like command that redirects the stdout and stderr of any internal command into a file. Eg :
./q4-p2"ls -l" output_p2.txt // output.txt must contain the output of Is -I
Deliverables:
- Q4.c containing the implementation for both parts (We should be able to test the implementation of both parts)
- Makefile to compile the program
- output_p1.txt and output_p2.txt containing the output from both parts.
Q 4 . Write a program in C to simulate the output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!