Question

In: Computer Science

How many new processes will be created by each of the following program segment: a.         int...

How many new processes will be created by each of the following program segment:

a.         int i;

            for (i = 0; i < 1000; i++)

                        if (fork()==0) break;

b.         int i;

            for (i = 0; i < 1000; i++)

                        if (fork()!=0) break;

c.         int i, pid;

            for (i = 0; i < 1000; i++)

                        pid = fork();

Solutions

Expert Solution

a.

The fork() system call is used to create a child process for the parent process. Using fork() system call n number of child processes can be generated from the same parent process.

Consider the given code.

The “for” loop iterates for 1000 times.

If the fork() system call is 0, it means the child process is created.

In the first iteration, the total number of processes = 2

In the second iteration, the total number of processes = 4

In the third iteration, the total number of processes = 8

The number of new processes = 2n -1

Here n =1000.

Then the number of new processes created = (21000 -1) processes.

b.

Consider the given code.

The “for” loop iterates for 1000 times.

If the fork() system call is not 0, it means the parent process is created.

In the first iteration, the total number of processes = 2

In the second iteration, the total number of processes = 4

In the third iteration, the total number of processes = 8

The number of new processes = 2n -1

Here n =1000.

Then the number of new processes created = (21000 -1) processes.

c.

Consider the code.

The “for” loop iterates for 1000 times.

In the first iteration, the total number of processes = 2

In the second iteration, the total number of processes = 4

In the third iteration, the total number of processes = 8

The number of new processes = 2n -1

Here n =1000.

Then the number of new processes created = (21000 -1) processes.


Related Solutions

Question: Including the initial parent process, how many processes are created by the program? And what...
Question: Including the initial parent process, how many processes are created by the program? And what is the value of i before each process terminates? Please draw the parent-child process hierarchy to justify your answer. #include<stdio.h> #include<unistd.h> int main() {           int i = 0;           if (fork() == 0) {                      ++i;                      if (fork() != 0)                              i = 3;                      else ++i;        fork();           }   else   {                       i = 5;                       if (fork() ==...
How many pairs of setae are there in each segment of the worm?Does each segment have...
How many pairs of setae are there in each segment of the worm?Does each segment have setae? What body region or segment are the walking legs attached to? What about the swimmerets? What is the function of these gills? Try to identify and explain what the crayfish had been eating: Inside the stomach locate the gastric mill, a hard serrated structure. Study it closely by running a finger along the tooth-like margin. What is this structure’s function? What are the...
What is the Θ( ) for each code segment below? (a) for( int i = 1,...
What is the Θ( ) for each code segment below? (a) for( int i = 1, i<= n, i = i*2){       some constant operation } (b) for( int i = 1, i<= n, i++){      for( int j = 2*i, j<=n, j++){           some constant operation      } } (c) for( int i = 1, i<= n, i = i*2){      for( int j = 1, j<=n, j = j*2){           some constant operation      } }
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
For the following factorial designs, indicate how many cells would be created, and then indicate how...
For the following factorial designs, indicate how many cells would be created, and then indicate how many main effects and interactions you would look for. a. 3 x 2 design b. 3 x 4 x 2 design c. 2 x 2 x 2 x 2 design Dovidio & Gaertner (2000) told students to make hiring recommendations for potential job candidates. Students read one application for a job from a fake candidate, recommending the candidate for the job (or not). The...
Consider the following program written in C syntax: void swap(int a, int b) { int temp;...
Consider the following program written in C syntax: void swap(int a, int b) { int temp; temp = a; a = b; b = temp;} void main() { int value = 2, list[5] = {1, 3, 5, 7, 9}; swap(value, list[0]); swap(list[0], list[1]); swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap? Passed by value Passed by reference Passed...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;       char B=10; cout<<”Enter Value of A”; cin<<A; show(A) show(50)          }       cin.get(); } int show(int x); { cout<<”Value is =” <<X cout<<endl; }
c programing language When a new program is executed, a new process is created with the...
c programing language When a new program is executed, a new process is created with the next available process ID. However, there are a few special processes that always have the same process ID, which are usually given the ID value less than 5 these are called system processes. Can you identify which of the two system processes have the process ID of 0 and 1 respectively?
How was the new religion of Islam created?
How was the new religion of Islam created?
Please comment, exactly how this program works? #include <stdio.h> int main() { int i,j; int a[1000];...
Please comment, exactly how this program works? #include <stdio.h> int main() { int i,j; int a[1000]; for(i=0;i<1000;i++) a[i]=1;    for(i=2;i<1000;i++) { if(a[i]==1){ for(j=i+1;j<1000;j++) {if(j%(i)==0) a[j]=0; } } } printf("print numbers are:\n"); for(i=2;i<=1000;i++) if(a[i]==1) printf("%d, ",i); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT