Question

Given the following pseudo-code, please show what the outputs will be at LINE A, B, C...

Given the following pseudo-code, please show what the outputs will be at LINE A, B, C and D. please put down “inconclusive if you think the CPU process scheduling could potentially result in multiple values for integer i. You will receive partial credit if you draw the process tree.

int i = 0;

int main(){

           

            if (fork() == 0) {

                        i++;

                        if (fork() == 0){

                                    if (fork() == 0){

                                                i++;

                                                print value of i; /*Line A*/

                                    } else {

                                                wait for this process’s child processes to stop;

                                                i++;

                                                print value of i; /*Line B*/                              

                                    }

                        } else {

                                    print value of i; /* LINE C*/

                                    wait for this process’s child processes to stop;                }

            } else {

                        wait for this process’s child processes to stop;

                        print value of i;   /* LINE D*/

           

            }

           

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

--> At Line A, value printed is 2. (because 2 increments will be performed from i = 0)

--> At Line B, value printed is 2. (because 2 increments will be performed from i = 0)

--> At Line C, value printed is 1. (because only 1 increment will be performed from i = 0)

--> At Line D, value printed is 0. (because no increments will be performed from i = 0)

Add a comment
Know the answer?
Add Answer to:
Given the following pseudo-code, please show what the outputs will be at LINE A, B, C...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following pseudo code. What are the possible outputs (.e., the complete output from each...

    Consider the following pseudo code. What are the possible outputs (.e., the complete output from each execution run of this program)? Explain in less than 50 words. Note: keep in mind that fork) may fail in that case no child process is created int main(int arge, char argvt int X- int CwO; re - fork(); 15 tre > 0) X=S; else x-rc +2: printf(" \n", x); return 0;

  • GIVEN CODE- FILL IN THE BLANK! #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h>...

    GIVEN CODE- FILL IN THE BLANK! #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> // Function ptototypes int readX(); void writeX(int); int main() /// chi read x ---> divi ---> write x into file ---> par read x --> sub--> write x into file---> chi read x-->etc {    int pid;           // pid: used to keep track of the child process    int x = 19530;       // x: our value as integer   ...

  • Complete the following C code by filling all “???”sto write a C program to create a...

    Complete the following C code by filling all “???”sto write a C program to create a child process. Before the child process is created, an integer variable A is defined and assigned value 10. Then in the child process, A is reduced by 5. After the child process completes, the parent process increases A by 5. Then what will A’s value be just before the parent process completes? Why? Write the code and run it to verify your answer. #include...

  • a) The purpose of the code on line 19, i.e., what does this line of code...

    a) The purpose of the code on line 19, i.e., what does this line of code accomplish? b) The purpose of the code on lines 21-27 (if statement). Make sure to explain each possibility handled by the if. 4 @author: student namel, [email protected] 5 author: student name2, [email protected] 7 @description: A program that demonstrates processes. 9 @course: ITSC 3146 10 @assignment: In-class activity [n] 12 13 14 #include<iostream> 15 #include«unistd.h> 16 17 int mainOl 18 19 20 21 pid_t id...

  • Linux & C code help with creating a child process and kills itself with SIGNAL. I...

    Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help to finish. Please provide output screen shot as well. Thank you! A Process creates a child process. Child process will print out "hello 0" "hello 1" ..... 1 line per second. After a certain number of seconds(user input), it kills itself WITH signal mechanism ONLY, don't use exit() on the child. You can use alarm()...

  • Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork...

    Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork a child process*/ pid = fork(); if (pid<0){ /*error occured*/ fprintf(stderr,"Fork failed\n"); return 1; } else if (pid == 0) { /*child process */ printf("I am the child %d\n",pid); execlp("/bin/ls","ls",NULL); } else { /*parent process */ /*parent will wait for the child to complete*/ printf("I am the parent %d\n",pid); wait(NULL); printf("Child Complete\n"); } return 0; } 1. Write program codes for 3.21 a and...

  • Write code that forks into two processes: a parent process, and a child process. Same as...

    Write code that forks into two processes: a parent process, and a child process. Same as the Regular version, except that your code must also be able to handle negative integers input from the command-line. If I call your code this way:     a03 -3 5 -7 The parent process should print out: Assignment 3     sum = -5 The sums produced from the test input I use will be in the range [-128 .. 127] -------------------------------------------------------------------------------------------------------------------- // Numbers from...

  • Can someone please explain this piece of java code line by line as to what they...

    Can someone please explain this piece of java code line by line as to what they are doing and the purpose of each line (you can put it in the code comments). Code: import java.util.*; public class Array { private Integer[] array; // NOTE: Integer is an Object. Array() {     super();     array = new Integer[0]; } Array(Array other) {     super();     array = other.array.clone(); // NOTE: All arrays can be cloned. } void add(int value) {    ...

  • What is the output of the following pseudo-code segment? A, B, C, or None of the...

    What is the output of the following pseudo-code segment? A, B, C, or None of the above ** In pseudo-code, you ignore syntax errors and focus on the logic ** score = 60 if (score >= 70) print "C" else if (score >= 80) print "B" else if (score >= 90) print "A" and score = 105 if (score >= 90 && score <= 100) print "A" else if (score >= 80) print "B" else print "C"

  • Operating Systems Questions (Please help if you can) 1. A computer has cache, main memory, and...

    Operating Systems Questions (Please help if you can) 1. A computer has cache, main memory, and a disk used for virtual memory. If a referenced word is in the cache, 20ns are required to access it. If it is in main memory but not in the cache, 60ns are required to load it into the cache (this includes the time to originally check the cache), and then, the reference is started again. If the word is not in main memory,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT