Synopsis 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 read that. • 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. • The following flow chart describes the flow of the program. Description 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. Read the sample input file, sample_in.txt. 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) Since the file is created in a Windows environment, the line terminator is ‘\r\n’. 3. Store the commands in a dynamically allocated array. sample_in.txt: pwd ls -l -a -F ps pwd -L -P ls cat makefile   P.S. Plese explain what each line is doing in comment please

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 13RQ
icon
Related questions
Question

Synopsis
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 read that.
• 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.
• The following flow chart describes the flow of the program.

Description
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. Read the sample input file, sample_in.txt. 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) Since the file is created in a Windows environment, the line terminator is ‘\r\n’.

3. Store the commands in a dynamically allocated array.

sample_in.txt:

pwd
ls -l -a -F
ps
pwd -L -P
ls
cat makefile

 

P.S. Plese explain what each line is doing in comment please

Read from file and write to dynamic array
fork()
Child Process
Run
5
Parent
command
Process
Write to pipe
Read from pipe
Write to screen using given
function, one by one
pipe
Performed multiple times
Transcribed Image Text:Read from file and write to dynamic array fork() Child Process Run 5 Parent command Process Write to pipe Read from pipe Write to screen using given function, one by one pipe Performed multiple times
File
sample_in - Notepad
Edit
pwd
ls -1 -a -F
ps
pwd - L -P
1s
cat makefile
View
Transcribed Image Text:File sample_in - Notepad Edit pwd ls -1 -a -F ps pwd - L -P 1s cat makefile View
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT