try to practice the concept of parent-child process, inter-process communication and some related system calls.
In this assignment, you will have a parent process that will create children processes to perform tasks and will collect the output from these children processes. There are three tasks that should be performed: • Read the input file that contains Linux shell commands. Parent process will create a child process to read that file and child process will return the content of that file in the form of a string using a shared memory area. • Execute the Linux shell commands read from the input file and execute them one by one. A child process will be created to execute these commands and the output will be returned by the child process in the form of string using pipe. • The parent process will write the output of commands to the screen.
Write a C program that includes the code for following tasks. Write all the code in single file:
1. Write the parent program as per the description in the “Synopsis”. The parent program must use fork system call to create children processes when required.
2. In order to create/use/clear shared memory buffers, use the POSIX API system calls mentioned in the book in chapter 3.
3. Read the sample input file, sample_in.txt. This file must be read by a child process and not the main/parent process. The name of the file must be given to the main/parent process through command line arguments.
a) This file contains one shell command per line.
b) The child process will write the content of the file to a shared memory area so that the parent process can read from there.
c) Once file reading is done, the child process will be terminated.
4. Copy the commands from the shared memory area to a dynamically allocated array.
5. Execute the commands one by one with the help of a child process:
a) Use a suitable version of exec system call to execute shell commands.
b) The child process must write the output of the command to a pipe from where the parent process will read it and display to the screen.
c) You may use only one child process by doing fork once to execute all the commands or fork again and again.
d) The parent process must use the provided output function, writeOutput(), to write the output to the screen. Invoke the output function iteratively, for each command. Warning: If you will not use this function to display the output then your outcome will not match with our outcome and you will be awarded zero.
6. The other implementation details are on your discretion and you are free to explore. 7. In order to test your code, use the sample_in.txt and compare the output of your program for this input file with the content of sample_out.txt. However, keep in mind that due to the nature of the commands, the output is specific to the content of the directory in which you run your program.
Get Help With a similar task to - try to practice the concept of parent-child process, inter-process communication and some related system calls.
Tutlance Experts offer help in a wide range of topics. Here are some of our top services:
- Math homework help
- Nursing homework help
- Statistics homework help
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Programming homework help
- Coursework writing help
- Term paper writing help
- Biology homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing services
- Chemistry homework help
Post your project now for free and watch professional experts outbid each other in just a few minutes.