Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

step 5 Re-write the program in Step 1 to create 4 processes so that each process iterates with a different delay taken as a command-line

step 5

Re-write the program in Step 1 to create 4 processes so that each process iterates with a different delay taken as a command-line argument. In this case, you will have 4 command-line arguments. When your program compiles without errors or warnings, upload the source file to Camino.

( pl do not copy the answer already in chegg. it is incomplete)

step1

/* C program to demonstrate the use of fork()*/ #include /* printf, stderr */ #include /* pid_t */ #include /* fork */ #include /* atoi */ #include /* errno */ /* main function */ int main() { pid_t pid; int i, n = 3000; // n is a delay in microseconds inserted in parent and child iterations printf(" Before forking. "); pid = fork(); if (pid < 0) { fprintf(stderr, "can't fork, error %d ", errno); exit(0); } if (pid){ // Parent process: pid is > 0 for (i=0;i<10;i++) { printf("\t \t \t I am the parent Process displaying iteration %d ",i); usleep(n); } } else{ // Child process: pid = 0 for (i=0;i<10;i++) { printf("I am the child process displaying iteration %d ",i); usleep(n); } } return 0; }

/* main function with command-line arguments to pass */ int main(int argc, char *argv[]) { The value of n then is taken as n = atoi(argv[1]); // n microseconds is taken as command-line argument Compile and run the program by typing ./ExecutableName 3000.

You may consider making sure that the user enters a delay in the command line using: if (argc != 2){ printf ("Usage: %s ",argv[0]); exit(0);

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

examples of recursive linear formula

Answered: 1 week ago

Question

Describe the linkages between HRM and strategy formulation. page 74

Answered: 1 week ago

Question

Identify approaches to improving retention rates.

Answered: 1 week ago