COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
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
make a screen capture showing the StegExpose results
Which of the following is not one of the recommended criteria for strategic objectives? Multiple Choice   a) realistic   b) appropriate   c) sustainable   d) measurable
Management innovations such as total quality, benchmarking, and business process reengineering always lead to sustainable competitive advantage because everyone else is doing them. a) True b) False
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
A+ Guide To It Technical Support
Computer Science
ISBN:9780357108291
Author:ANDREWS, Jean.
Publisher:Cengage,