Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need to program this in C - any help? the starter code for exec_another: #include #include #include //exec(ls) will execute whats in directory //execvp(cmd, parameter)

need to program this in C - any help?image text in transcribed

the starter code for exec_another:

#include #include #include //exec("ls") will execute whats in directory //execvp(cmd, parameter) --> in this case it is "./greeter" for the command, argv[1], NULL] int main(int argc, char** argv) {

assert(argc >= 2); char* cmd = "./greeter"; char* const parmList[] = {cmd, argv[1], NULL}; char* param_Arr[] = ["./greeter", argv[1], NULL]; pid_t child = fork(); if(child > 0){ //child } else { //parent } // TO DO

printf("Child process (pid: %d) exited with status %d. ", getpid(), ?/* TO DO */); printf("Parent Process (pid: %d) exiting now. ", getpid()); return 0; }

Part 2: Execute Another Program. In this part of the assignment, you will modify a small C program exec another.c that will execute another program For the purpose of this assignment, we have written a very small and polite C program named greeter.c that takes a string from the command line, and greets by simply saying hello. For example, if you run the greeter program with argument World (./greeter World), it will print "Hello World!" on the screen The source code for the greeter program is attached in the started folder. Do not modify this program Note that, at a successful execution it exits with status 3 (aka returns 3) Step 1. In your program, you will use fork) to create a child process. Inside the child process, using execvp) function, you will execute the greeter program. Take a string from the command line to pass to the greeter program. Step 2. The parent process waits for the child process to exit and then prints out the process id and exit status of the child process using the following format string: "child process (pid: %d) exited with status %d. Step 3. Finally, the parent process prints out its own process id using the following format and exits. "Parent Process (pid: %d) exiting now . " Include all the necessary header files so that the code does not give any warning at compile time. You are encouraged to use the man pages for this. After successful execution, your output will be somewhat like this. ./exec another World Hello World! Child process (pid: 1123) exited with status 3 Parent Process (pid: 1122) exiting now. Part 2: Execute Another Program. In this part of the assignment, you will modify a small C program exec another.c that will execute another program For the purpose of this assignment, we have written a very small and polite C program named greeter.c that takes a string from the command line, and greets by simply saying hello. For example, if you run the greeter program with argument World (./greeter World), it will print "Hello World!" on the screen The source code for the greeter program is attached in the started folder. Do not modify this program Note that, at a successful execution it exits with status 3 (aka returns 3) Step 1. In your program, you will use fork) to create a child process. Inside the child process, using execvp) function, you will execute the greeter program. Take a string from the command line to pass to the greeter program. Step 2. The parent process waits for the child process to exit and then prints out the process id and exit status of the child process using the following format string: "child process (pid: %d) exited with status %d. Step 3. Finally, the parent process prints out its own process id using the following format and exits. "Parent Process (pid: %d) exiting now . " Include all the necessary header files so that the code does not give any warning at compile time. You are encouraged to use the man pages for this. After successful execution, your output will be somewhat like this. ./exec another World Hello World! Child process (pid: 1123) exited with status 3 Parent Process (pid: 1122) exiting now

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

ISBN: 3319234609, 978-3319234601

More Books

Students also viewed these Databases questions