In C language, Write a program called minishell that creates two child processes: one to execute 'ls -al'...

90.2K

Verified Solution

Question

Programming

In C language,

Write a program called minishell that creates two childprocesses:
one to execute 'ls -al' and the other to execute‘grep minishell.c’.

After the forks, the original parent process waits for bothchild processes to finish before it terminates. The parent shouldprint out the pid of each child after it finishes. The standardoutput of 'ls -al' process should be piped to the input to the'grep minishell.c' process. Make sure you close the unnecessaryopen files for the three processes. The output should be the oneline that includes the directory entry for minishell.c. You willneed to call the source file minishell.c for this to workproperly.

Please comment thoroughly so i can follow the logic.

Answer & Explanation Solved by verified expert
4.5 Ratings (684 Votes)
ANSWER GIVEN THAT Answering the fist part of the question where the parent should wait for the two child process to finish include include include include include int main pidt pid1 pid2 int status create the first child process if pid1 fork 0 perrorerror forking first child return 1 if pid1 0 first child process execute ls al char argsbinlsal NULL execvpargs0 args control does not    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students