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
Concept explainers
Question
Chapter 10.3, Problem 10.1PP
Program Plan Intro
Opening and Closing files:
Using “Open” function, a process can open an existing file or generates a new file.
- This function is used to converts a filename to a file descriptor and returns the result as a descriptor number.
- The descriptor returned is always the lowest descriptor that is not presently open in the process.
- Each process in the LINUX begins life with three open files.
- Descriptor 0 – standard input.
- Descriptor 1 – standard output.
- Descriptor 2 – standard error.
- The “open” function consists of three arguments. That is “Open(filename, flags, mode)”.
- The argument “filename” defines the name of the given file.
- The argument “flags” represents how the process plans to access the file. Some flags names are as follows.
- O_RDONLY – it means reading only.
- O_WRONLY – it means writing only.
- O_RDWR – it means reading and writing.
- The “mode” argument identifies the access permission bits of new files.
Example:
The example for open an existing file for reading is shown below:
sample1 = Open("foo1.txt", O_RDONLY, 0);
From the above “open” function,
- The filename is “foo1.txt”.
- Flag name is “O_RDONLY”.
- Mode is “0”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Problem 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…
(a) Assume that five generation units with third order cost
function (F, (R) = A; P+ B;P+C; P; + D;) are in the circuit.
Write a computer program using any abitrary programming
longuage (MATLAB, C++, C#, Python,.) to calculate economic
load dipatch (ELD) using first order gradient method.
Note that all parameters and variables should be defined
inside the
program (at
tirst lines) such that units' characteristics
and demand can be changed easily. Neglect grid losses.
jusing dynamic programming (DP) methed.
(B+C) x (D+E)
F
1. Write code to implement the expression: A =
on 3-, 2-, 1- and 0-address
machines. In accordance with programming language practice, computing the expression should
not change the values of its operands.
2. Solve the following:
a) In a computer instruction format, the instruction length is 11 bits and the size of an address
field is 4 bits. Is it possible to have:
5 2-address instructions, 45 1-address instructions and 32 0-address instructions using the spec-
ified format? Justify your answer.
3. Suppose a computer using direct mapped cache has 232 bytes of byte-addressable main memory
and a cache size of 512 bytes, and each cache block contains 128 bytes.
a) How many blocks of main memory are there?
b) What is the format of a memory address as seen by cache, i.e., what are the sizes of the tag,
block, and offset fields?
c) To which cache block will the memory address 0x13A4498A map?
Chapter 10 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 10.3 - Prob. 10.1PPCh. 10.8 - Practice Problem 10.2 (solution page 915) Suppose...Ch. 10.8 - Practice Problem 10.3 (solution page 915) As...Ch. 10.9 - Prob. 10.4PPCh. 10.9 - Practice Problem 10.5 (solution page 916) Assuming...Ch. 10 - Prob. 10.6HWCh. 10 - Prob. 10.7HWCh. 10 - Write a version of the statcheck program in Figure...Ch. 10 - Consider the following invocation of the...Ch. 10 - Prob. 10.10HW
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (Chapter 10) Here again is the example used in our lecture to show the difference between scoping with blocks and dynamic scoping; fun g x = let val inc = 1; fun f y = y + inc; fun h z = let val inc = 2; in f z end; in h x end; Annotate it as follows: Draw a circle around every block, and number the blocks. Identify each definition of a name. For each definition, describe its scope in terms of your block numbers. For each occurrence of a name (other than a definition of that name), show which definition is used to bind it. Check that this agrees with your scopes.arrow_forward(C Program) Write a recursive function called PrintLinkedList() that outputs the integer value of each node in a linked list. Function PrintLinkedList() has one parameter, the head node of a list. The main program reads the size of the linked list, followed by the values in the list. Assume the linked list has at least 1 node.arrow_forward(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.arrow_forward
- (h) (Extra Credit!) Write a for-loop to implement a hill-climbing algorithm for the original constrained problem. Note that this algorithm must reflect the link be- tween small increases in x and y as captured through the constraint and so is поп-trivial.arrow_forward(Use Python) Use the Design Recipe to write a function, print_histogram that consumes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list. You may assume that only integers are passed to this function. Your function should ignore negative values. Test Result print_histogram([ 2, 0, 4, 1]) ** ***** print_histogram([10, 5, 3, -1, 8]) **************************arrow_forward2) Implement the second phase of Software Development Method (SDM) for this following problem statement. Write a program to calculate and display the volume and surface area of a cube block. You also need to consider the following condition : The sides length must be greater than zero.arrow_forward
- 1. (Assembly Language Programming) Write a procedure gcd for finding the greatest common divisor (GCD) of two positive integers x and y, which is described in the C code below. int gcd (int x, int y) { if (y 0) == return x; else return gcd (y, x % y); } Assume that x and y are passed to procedure gcd via X4 and X5 and the result is returned in X2. Note that x % y is the remainder of x / y.arrow_forward(QUESTION) Using the required programming language (python, matlab, etc.) plot the variation of pressure on the piston surface as a function of time until the piston moves 9 m, with the help of the following commands below. This problem will be solved for U_p =1, 4, 16, 64, 256 m/s. We'll assume that the time starts at t = 0 when the piston starts moving. (PLEASE TAKE A SCREENSHOT OF THE PLOTTING AND OTHER RESULTS.) Note: Since we don't have the exact time intervals or the rate at which the piston moves, we'll assume a constant speed and divide the distance by the speed to get the time taken. (QUESTION) COMMANDS import matplotlib.pyplot as plt import numpy as np # Given parameters diameter = 0.1 # meters length = 10 # meters initial_pressure = 10e3 # Pascals initial_temperature = 288 # Kelvin # Convert diameter to radius radius = diameter / 2 # Calculate initial and final volumes initial_volume = np.pi * radius**2 * length final_volume = np.pi * radius**2 * (length - 9) # Calculate…arrow_forwardC++ Problem 1: (Monte Carlo Experiments) The Monte Carlo method is used in modeling a wide-range of physical systems at the forefront of scientific research today. Let’s consider the problem of estimating the area of the region x 2 + 2y 2 ≤ 1 by utilizing the Monte Carlo method. This region is enclosed by a blue ellipse, which is inscribed in a 2 × 2 red square (shown in the figure below). The experiment simply consists of throwing darts on this figure completely at random (meaning that every point in the red square has an equal chance of being hit by the dart). You keep throwing darts at random. All of the darts fall within the square, but not all of them fall within the ellipse. If you throw darts completely at random, this experiment estimates the ratio of the area of the ellipse to the area of the square, by counting the number of darts within each area. Program this Monte Carlo method to compute the area of the blue ellipse using different numbers of darts. For each experiment,…arrow_forward
- 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.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(C PROGRAMMING ONLY) 2. Weird Treasure Chestby CodeChum Admin I'm now in the middle of the jungle when I saw this weird treasure chest. It seems that if I properly place the address of a certain number, I get a very weird result! Instructions: In the code editor, you are provided with a treasureChestMagic() function which has the following description:Return type - voidName - treasureChestMagicParameters - an address of an integerDescription - updates the value of a certain integer randomlyYou do not have to worry about how the treasureChestMagic() function works. All you have to do is ask the user for an integer and then call the treasureChestMagic() function, passing the address of that integer you just asked.Finally, print the updated value of the integer inputted by the user.Input 1. An integer Output Enter n: 10Treasure Chest Magic Result = 13arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr