Question

In: Computer Science

What is the output of the following program? Slightly modify the program so that: [Pts. 10]...

  1. What is the output of the following program? Slightly modify the program so that: [Pts. 10]
    1. The Parent process calculates the val such a way that its value is 20 and it prints “This is parent process and val = 20”. Also, slightly modify
    2. The child process calculates the val such a way that its value is 25 and it prints “This is child process and val = 25”.

int main() {

int val = 15;

int pid;

if (pid = fork()){

wait(pid);

printf(“This is parent process and val = “);

}

else{

printf(“This is child process and val = “);

val++;

}

printf("%d\n", val);

return val;

}

Solutions

Expert Solution

Output:

This is child process and val = 16                                                                                                              

This is parent process and val = 15

Program:

int main() {

int val = 20;
int pid;
  
if (pid = fork())
{
wait(pid);
printf("This is parent process and val = ");
}
  
else{
printf("This is child process and val = ");
val+=5;
}
  
printf("%d\n", val);
return val;
}


Related Solutions

Modify the Movie List 2D program -Modify the program so it contains four columns: name, year,...
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) -Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating def list(movie_list): if len(movie_list) == 0: print("There are no movies in the list.\n") return else: i = 1 for row in movie_list: print(str(i) + ". " + row[0] + " (" + str(row[1]) + ")") i += 1...
•Modify p4.c so that the output file p4.output is created but also displayed to standard output...
•Modify p4.c so that the output file p4.output is created but also displayed to standard output ( the screen ). This should be done by another instance of exec(). •Implement the pipe() command to do the following: $> grep –o else p4.c | wc –l p4.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <sys/wait.h> int main(int argc, char *argv[]) { int rc = fork(); if (rc < 0) {     // fork failed     fprintf(stderr, "fork...
Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks:...
Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. For example if there were 3 contestants, the expected revenue would be displayed as: Revenue expected...
- What is the output of the following program?                      StackPT stk1 = new ArrayStackPT( 10...
- What is the output of the following program?                      StackPT stk1 = new ArrayStackPT( 10 ); StackPT stk2 = new ArrayStackPT( 10 ); StackPT stk3 = new ArrayStackPT( 10 ); StackPT stk4 = new ArrayStackPT( 10 ); QueuePT q1 = new ArrayQueuePT(10); int n = 12; while (n > 0){   stk1.push(n%2); n = n/2; } String result = ""; while (! stk1.isEmpty()){ result += stk1.pop()+ " "; } System.out.println("the output of stk1 : "+result); //___________ for(int i =0; i<10;...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm:...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when the program runs. Have the program request the number of initial numbers to be entered." //C++ Program 7.14 as follows #include #include #include #include using namespace std; int main() { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector partnums(n, n + NUMELS); cout << "\nThe vector initially has the size of " << int(partnums.size()) << ",\n and...
Modify the below program so that the following two conditions are met: 1. Each child terminates...
Modify the below program so that the following two conditions are met: 1. Each child terminates abnormally after attempting to write to a location in the read-only text segment. 2. The parent prints output that is identical (except for the PIDs) to the following: child 12255 terminated by signal 11: Segmentation fault child 12254 terminated by signal 11: Segmentation fault Hint: Read the man page for psignal(3) ___________________________________. #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <sys/types.h>...
Modify the Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase...
Modify the Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9 to 8, 8 to...
Modify the AlienDirection program from this chapter so that the image is not allowed to move...
Modify the AlienDirection program from this chapter so that the image is not allowed to move out of the visible area of the window. Ignore any key that would allow this to happen. *Ask if you have any questions about the assignment I will try to clarify Textbook - JAVA FOUNDATIONS: INTRODUCTION TO PROGRAM DESIGN AND DATA STRUCTURES 5TH EDITION Starter Code Provided : import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.stage.Stage;...
In c++, modify this program so that you allow the user to enter the min and...
In c++, modify this program so that you allow the user to enter the min and maximum values (In this case they cannot be defined as constants, why?). // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT