You need to write a C program (location: task-1/solution-1.c) that will take a single command line argument. The command line argument will be the name of a file. The file will contain a sequence of Unix/Linux commands for file manipulations: one command in each line. Your program needs to execute each of these commands. For this task, you must not use system(); instead, you have to use fork(), execvp(), wait()/waitpid() functions.

For each command, your program will spawn a process using fork() which will carry out the given file operation using exec() (or one of its variants). You can use execvp(). See this link ([1]) for exec() man-page and this link ([2]) for a pictorial description of its family.

Assumptions: You can safely assume that each line will have a maximum of 1024 characters including the newline character at the end of the line. The file contains only two types of commands: (1) cp < source-file-path> < destination-path>, and (2) mv < source-file-path> < destination-path>.

Error checking: Your program should do appropriate error checking. In case of an error, your program must print the following error message: "An error has occurred\n" and then exit with the error code 1, e.g., using exit(1).

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.