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
expand_more
expand_more
format_list_bulleted
Question
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
- 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...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Problem 3) One of the automatic memory deallocations is based on scope of a variable stored in a
memory. Give a Java/etc code in which variable will be deallocated when scope of the variable is over.
Explain in your example when the variable is stored in the memory and when it is deallocated.
### Given the resolution of the problem 5.102 below, develop a python program (without using numpy) that shows the found temperature distribution
Problem 1 jt"¡1, The following program is run on a machine where memory reference
instructions take 8 cycles, arithmetic instructions take 6 cycles, and branches take 3 cycles. It is
known that the “sqrt" procedure executes 7 instructions and requires 30 clock cycles.
$s0, 20 ($s2)
$t1, $s3, $s3
lw
add
j
L1
$t1, $t1, $t1
$t1, $t1, $6
$a0, 0 ($t1)
sqrt
addi $s3, $s3, 1
beq $s0, $v0, Exit
add
L1:
add
lw
jal
(a). How long will it take to run this program if the machine has a 500 MHz clock?
(b). What is the CPI for this program?
Chapter 8 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 8.2 - Prob. 8.1PPCh. 8.4 - Prob. 8.2PPCh. 8.4 - Prob. 8.3PPCh. 8.4 - Prob. 8.4PPCh. 8.4 - Practice Problem 8.5 (solution page 797) Write a...Ch. 8.4 - Practice Problem 8.6 (solution page 797) Write a...Ch. 8.5 - Practice Problem 8.7 (solution page 798) Write a...Ch. 8.5 - Prob. 8.8PPCh. 8 - Prob. 8.9HWCh. 8 - In this chapter, we have introduced some functions...
Ch. 8 - How many hello output lines does this program...Ch. 8 - How many "hello' output lines does this program...Ch. 8 - Prob. 8.13HWCh. 8 - How many hello output lines does this program...Ch. 8 - How many "hello lines does this program print?Ch. 8 - Prob. 8.16HWCh. 8 - Prob. 8.17HWCh. 8 - Consider the following program: Determine which of...Ch. 8 - How many lines of output does the following...Ch. 8 - Use execve to write a program called my1s whose...Ch. 8 - What are the possible output sequences from the...Ch. 8 - Write your own version of the Unix system function...Ch. 8 - One of your colleagues is thinking of using...Ch. 8 - Modify the program in Figure 8.18 so that the...Ch. 8 - Write a version of the fgets function, called...
Knowledge Booster
Similar questions
- (a) A ssume that five generation unıts with third order cost function (F, (P) = A; P+ B;P+C; P; + D;) are in the circuit. Write a computer program using any arbitrary programming language (MATLAB, C++, C#, Python,.) to calculate economic load dispatch (ELD) using first order gradient method. Note that all parameters and variables should be defined inside the program (at tirst limes) such that units' charactenistics and demand can be changed easily. Neglect grid losses. O using lambda - iteration method.arrow_forwardPRACTICE PROBLEM #1 a) Write pseudo code algorithm for a SIGN(X) function. b) Write Using the SIGN(X) function above, write the pseudo code algorithm that chooses the nearest distance solution from a set of possible solutions for either (prismatic or revolute joints). Assume the joint has a limit dЄ[0,40mm], OE[-4ñ/3, 4ñ/3].arrow_forwardProblem 1 Computer 1 (C1), with a clock rate of 3 GHz, runs a program in 40 seconds. Computer 2 (C2), with a clock rate of 9 GHz, runs the program in 10 seconds. The number of instructions is the same for both computer 1 (C1) and computer 2 (C2). a) What is the number of clock cycles executed by computer 2 (C2)? b) If the average CPI for computer 1 (C1) is 3, what is the average CPI for computer 2 (C2)?arrow_forward
- Q1) Consider a simple traffic light system to regulate safe pedestrian crossing on a busy lane. Consider the following system requirement:(SysReq:)The traffic lights shall allow pedestrians to safely cross the lane by stopping cars together with the following software requirements: (SofReq1:)The light switch for pedestrians will be set to 'green' within x seconds after the pedestrian button has been pressed. (SofReq2:)The light switch for cars will be set to 'red' at least y seconds before the light switch for pedestrians is set to 'green'. Find missing environment assumptions and domain properties that are necessary to build the following satisfaction argument: {SofReq1, SofReq2, assumptions?, domain properties?} =SysReq Are the missing domain properties adequate? Are the missing assumptions realistic?arrow_forwardPlease help step by step for R program with a final code for understanding thank you.arrow_forward(c) An electronic rainfall depth measurement device is developed to collect the data from the past 7 days as shown in Table 1 to study the weather condition at UniMAP. Table 1 [Jadual 1] Location: UniMAP Day Rainfall Depth (mm) 5.9 1 2 6.7 3 2.4 7.8 5.2 4 5 1.8 7 3.5 (i) Write a program in C to receive the values of rainfall depth and display the number of days with light rain ( 7.6 mm) from the record in Table 1. (ii) Rewrite the program in (c)(i) to identify and display the day with the lowest value of rainfall depth, the day with the highest value of rainfall depth and the average value of rainfall depth for the past 7 days.arrow_forward
- PROBLEM 24 - 0578: (a) Water flows into a tank at a constant rate Q. Q is determined by the position of a valve connected to the inflow pipe. Write a FORTRAN program to simulate this system, using Euler's method, from time t = 0 to t = tf if V(0) = Vo and the capacity of the tank is C units of volume. Compare the Euler approximations with the exact values. (b) A hole is made in the bottom of the tank allowing water to flow out at a constant rate, Q1. Modify the program of part (a) to simulate this system. YALVE a YALVE WATER WATER yu WATER LEVEL TANK WATER LEVEL TANKarrow_forwardPLEASE WRİTE A PARAMETİC PROGRAM TO SOLVE !!! ( PYTHON)arrow_forwardPROBLEM 21 - 0533: Write a BASIC program to solve Laplace's equation (a²V/Əx?) + (a²V/ay²) = 0. Consider a rectangular 8 by 8 grid %3D with boundary conditions such that 3 sides are assumed to be at a potential of 100. The remaining side is at zero potential as shown. Solution: We use the replacement of partial derivatives by central differencesarrow_forward
- 2. Full code and plotting neweful. Task(5): Run the following code and note down the output. Also use real, imag and abs functions to plot real part, imaginary part and magnitude.>> n = [0:5]; x = exp ((2+3j)*n) Task(7): Write a program in Matlab to generate 1.5 s of a 50 Hz Saw tooth Waveform withsample rate fs = 10000 and plot 0.2 s of the generated waveform Task(1): Write a MATLAB code to sum unit step and unit ramp function . subject is signal and system please solve me all three.arrow_forwardQuestion 2 Using the incomplete programming code given, complete the code using dynamic programming with memory function, to reproduce the results in the following Table 1. (C++) #include<iostream>using namespace std; // max knapsack capacity // *** WRITE YOUR CODE HERE ***// num of items // *** WRITE YOUR CODE HERE ***// weight of each item // *** WRITE YOUR CODE HERE ***// value of each item // *** WRITE YOUR CODE HERE ***// variable for dynamic programming matrix // *** WRITE YOUR CODE HERE *** //==========================================// Dynamic programming function: recursive// ========================================= // ALGORITHM F(i,j) // int value // if F[i,j] is not filled yet (-1): // (start with j = W, i = n) // if capacity j < current item's weight w[i]: // value = recall F(i-1, j) // else: // we can include current item,…arrow_forwardProblem (5) Consider the code in main() below. Write code (in C++) to close as many memory leaks as possible. If there is still some memory leaking, describe why you cannot take care of it. int** pp; int* p1, p2; int x = 2; p2=new int; pp=new int*; *pp = p2; = new int; %3D p2 **pp = p1 *p2; *pp; p2 = new int;arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education