Question: 1) Please answer full question (a-c located at bottom) dealing with CMD line arguments and fork and wait (unix programming) #include int main(int argc, char

1) Please answer full question (a-c located at bottom) dealing with CMD line arguments and fork and wait (unix programming)

#include

int main(int argc, char **argv) {

printf("argc: %d ", argc);

int i; for (i = 0; i < argc; i++) { printf("argv[%d]: %s ", i, argv[i]); }

return 0; }

#include #include #include #include #include

int main(int argc, char **argv) {

pid_t pid = fork(); pid_t terminated_pid; if (pid > 0) { printf("I am a parent process (pid: %d) ", getpid()); printf("My child process's process ID is %d ", pid);

// wait option A terminated_pid = wait(NULL); printf("A child process (pid: %d) has been terminated. ", terminated_pid);

// // wait option B // terminated_pid = waitpid(pid, NULL, 0); // printf("A child process (pid: %d) has been terminated. ", terminated_pid);

} else if (pid == 0) { printf("I am a child process (pid: %d) ", getpid()); printf("My parent's process ID is %d ", getppid());

} else { printf("Failure creating child process (error number: %d) ", errno); }

return 0; }

#include #include #include #include #include #include #include

int main(int argc, char **argv) {

int i; pid_t pid; pid_t terminated_pid;

int n_child = strtol(argv[1], NULL, 10); printf("The number of child processes: %d ", n_child);

// TODO: Create child processes

// TODO: Wait for child processes to terminate

return 0; }

[ Code Snippet related part a and b ] pid_t pid = fork(); if (pid > 0) { // A } else if (pid == 0) { // B } else { // error: process creation }

a). Where you should write codes for parent process, A or B? b). In the body A, what kind of information the variable "pid" contains? c). Let's assume that there is an executable "hello.exe". If you run the following command, what are the values of (1) argc and (2) argv[2]? ./hello.exe operating systems 4061 A3 (1). argc: A3 (2). argv[2]:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!