Question
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?
the starter code for exec_another:
#include
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started