Question: Write a program that takes a filename as a command - line argument and performs the following steps: 1 . Open the file specified as

Write a program that takes a filename as a command-line argument and performs the
following steps:
1. Open the file specified as the command-line argument.
2. Read contents of the file one-line at a time.
3. Use fork-exec to create a new process that executes the program specified in the
input file along with the arguments provided.
4. The parent process will make note of the time the program was started (you can
use a timer such as the time function defined in to capture the time before
the fork method is invoked, you can find out more about time function by
typing man time).
5. Then the parent process will wait for the child process to complete and when the
child process terminates successfully, the parent process will capture the time the
child process completed (you can again use a timer function to capture the time
when the wait function returns).
6. Open a log file (say, output.log) and write the command executed along with
arguments, start time of the process, and the end time of the process separated by
tabs. Use ctime function to write the time in a human readable form.

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!