Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
Question
Book Icon
Chapter 8.4, Problem 8.2PP

A.

Program Plan Intro

Given code:

//Include the necessary header files

#include <stdio.h>

#include "csapp.h"

//Define a main()

int main()

{

//Initialize the variable x as 1

int x=1;

//Check the condition

if(fork()==0)

//Print the statement

printf("p1: x=%d\n", ++x);

//Print the statement

printf("p2: x=%d\n", --x);

//Exit

exit(0);

}

Explanation:

The given code is used to print the output of the child and parent processes.

In the given code, the main program initializes the variable “x” as “1”.

  • The “if” condition check, function “fork()” is equal to zero.
    • Condition is true, print the value of “x” by incrementing “1”. So, the value of “x” becomes “2”.
  • Otherwise, print the value of “x” by decrementing “1”. So, the value of “x” becomes “1”.
  • Exit from the program.

B.

Explanation of Solution

Output of the parent process:

P2: x = 0

Explanation:

In the given code, the main program initializes the variable “x” as “1”.

  • The parent process check the condition, if the function “fork()” is equal to zero...

Blurred answer
Students have asked these similar questions
Problem 3 (#2.1.32).Explain why (A×B)×(C×D)and A×(B×C)×D are not the same
3. The diagram below shows the main land routes for vehicular traffic between points A and G in a city. The figures in the arcs represent the cost of traveling between each pair of nodes.   a) Manually apply Dijkstra's algorithm to find the cheapest route between A and G (visited nodes and total distance). b) Formulate a linear programming problem in extended form, to determine the shortest route to travel from A to G. Do not use subscripts, name 14 variables, for example XFE would be the variable that indicates that the arc from F to E is used. c) If there is a fixed cost for visiting each node, modify the formulation of the problem to include said fixed cost in the objective function, and the variables and restrictions that are required.     NODE A B C D E F G FIXED COST 25 18 32 20 28 18 34
PROBLEM 12. [TIME ALLOWED = 5 MINUTES]   Give the contrapositive and converse of the following proposition:   “If it is sunny, then I will go swimming.”
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr