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
(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.
(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.
(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.
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
- 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_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_forwardProblem 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_forwardPLEASE WRİTE A PARAMETİC PROGRAM TO SOLVE !!! ( PYTHON)arrow_forward
- PROBLEM 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_forward1. (Shortest Path) Please find the shortest path between the blue triangle and red tri- angle as Figure 1. Please explain your approach and develop the computationally efficient algorithm to get the results. Can you obtain (or estimate) the time com- plexity and memory complexity of your algorithm? 麗arrow_forwardProblem 2 (5 pts) Write a Python program that plays the game Ro-Sham-Bo (a.k.a., Rock, Paper, Scissors) for a player and a computer opponent. The player selects one of the options listed in a console prompt, then the computer randomly selects an option as well. The winner of the game is determined as follows: Rock beats Scissors - Scissors beats Paper - Paper beats Rock The same selection results in a tie. Your program must do the following: Prompt the player to enter a selection in the console. Provide instructions to user on what is a valid input. For example, you can have the integers 1, 2, and 3 represent the selection, or use the words rock, paper, scissors, etc. Check that the user entered valid input. If the entry is invalid, the program needs to inform the user of the invalid input and can end, or re-prompt the user for their entry. Generate a random selection for the computer's choice. You can use a random integer and follow the same rules as was stated to the user. - Display…arrow_forward
- Question 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_forward3. 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 34arrow_forward(a) Given the following program in Figure 5. 1 #include 2 int main () 3 { int x = 10; while (x >= 1) { if (x84==0) { printf ("x = %d\n",x) ; 5 6 7 8 x++; 9 10 return 0; 11 } Figure 5arrow_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