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...
How many race conditions does attackers have to win in the following program? int main() {...
How many race conditions does attackers have to win in the following program? int main() { struct stat stat1, stat2; int fd1, fd2; if (access("/tmp/XYZ", O_RDWR)) { fprintf(stderr, "Permission denied\n"); return -1; } else fd1 = open("/tmp/XYZ", O_RDWR); if (access("/tmp/XYZ", O_RDWR)) { ' fprintf(stderr, "Permission denied\n"); return -1; } else fd2 = open("/tmp/XYZ", O_RDWR); // Check whether fd1 and fd2 have the same inode. fstat(fd1, &stat1); fstat(fd2, &stat2); if(stat1.st_ino == stat2.st_ino) { write_to_file(fd1); } else { fprintf(stderr, "Race condition detected\n");...
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...
How was the new religion of Islam created?
How was the new religion of Islam created?
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...
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?
For each of the following, describe how to implement the operation of the variable "int x"...
For each of the following, describe how to implement the operation of the variable "int x" using only bitwise, addition, and subtraction operators (<<, >>, +, -, &, |, ^, ~) A) x * 2 B) x * 14 C) x * -44 D) x * 1023 Problem 2. Floating point encoding. Write out the 32 bit IEEE floating point binary representation for each of the following numbers: A) 1.0 B) -2.0 C) -1000000.00 D) nan E) -inf F) 3.402823e38
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT