Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in C. This is the starter code. #include #include #include #include #include int main(int argc, char ** argv) { pid_t child; int exitStatus;

Please code in C.

This is the starter code.

#include  #include  #include  #include  #include  int main(int argc, char ** argv) { pid_t child; int exitStatus; // at least, there should be 3 arguments // 2 for the first command, and the rest for the second command if (argc  

image text in transcribed

Part 1. (100 points) run2 should use the fork and exec functions to run two commands specified on the command line. The arguments passed to run2 are stored in the array argv. The first executable is argv [1] and it takes one, and only one, argument, which is in argv[2]. The second executable is argv [3], and the rest of arguments, if any, are arguments to argv[3]. In the following example, the two commands are cat Makefile and ls a b. $./run2 cat Makefile ls a b There are multiple functions in the exec family of functions, which behave in slightly different ways. You should use execlp to run the first command, and execvp to run the second command. You should read the manpage for exec, and understand why these variants are sensible choices here. If any functions like fork() fail, report the error using perror() and exit from the process. The parameter to perror () is the function name followed by parentheses, as in the following examples. perror("fork()"); perror ("execlp()"); For each child process successfully created, the parent process waits for the child process to exit and prints out the exit status of the child process using the following format string: "exited =%d exitstatus =%d The first number is from WIFEXITED, and the second is from WEXITSTATUS. Study the demo code or the manuals to learn WIFEXITED and WEXITSTATUS. Below are some examples of using run2. You may have more creative ways to use the program. $./run2 vi run2.c make $./run2 touch run2.c make run2 $./run2 echo 1 ./run2 echo 2 . /run2 echo 3 ls *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

1 2 7 to 8 bit binary twos complement

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago