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.
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?
(a) Assume that five generation units 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 first lines) such that units' characteristics
and demand can be changed easily. Neglect grid losses.
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) Assume that five generation units 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 longuage (MATLAB, C++, C+, Python,..) to calaulate economic load dispatch (ELD) using first order gradient method. Note that all parameters and variables should be defined program (at tirst lines such that units' charactenistics and demand can be changed easily. Neglect grid losses. o using second order gradient method. inside thearrow_forward(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_forwardI need help with problem 17arrow_forward
- PRACTICE 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 10 void fun (void) { Consider the following C program. int a, b, c; //definition 1 while (. .) { int b, c, d; //definition 2 For each of the four marked points 1 in this function, list each visible ... while (. . .) { variable, along with the number of int c, d, e; //definition 3 2 the definition statement that } defines it. 3 } 4arrow_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
- (7) Discrete structure: Please solve it on urgent basis: Question # 7: Show that at least ten of any 64 days chosen must fall on the same day of the week.arrow_forwardQ1) 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_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 No.1 Given: Eight (8) Queens and 8 x 8 chess board Goal: Arrange the 8 Queens in the 8 x 8 chess board as given in the layout above such that only one (1) Queen will be placed in any column, row, and diagonal/s. That is, no two or more Queens are placed in any column, row, and diagonal/s. Solve the problem set by the giving the solution, which is the sequence of steps, that will satisfy the goal. NOTE: The respective Queens are move in their column location only. For example, QA is move along column A, QB column B, and so on. However, you need to give the remaining moves to attain the required goal. Set the column labels from left to right A, B, C, D, E, F, G, and H, respectively. Set the row labels from top to bottom 8, 7, 6, 5, 4, 3, 2, and 1, respectively.arrow_forwardPROBLEM 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_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
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