Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

What is meant by and what are some examples of globalization?

Answered: 1 week ago