New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
computer systems a programmers perspective
Computer Systems A Programmers Perspective 3rd Global Edition Randal E. Bryant, David R. O'Hallaron - Solutions
As before, suppose the disk file foobar.txt consists of the six ASCII characters foobar. Then what is the output of the following program? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include "csapp.h" int main() { 16 17 } int fd; char c; fd = Open ("foobar.txt", O_RDONLY, 0); if (Fork () SS 0) { Read (fd,
Implement a place function for the example allocator.static void place(void *bp, size_t asize)Your solution should place the requested block at the beginning of the free block, splitting only if the size of the remainder would equal or exceed the minimum block size.
Describe a reference pattern that results in severe external fragmentation in an allocator based on simple segregated storage.
Assuming that the disk file foobar.txt consists of the six ASCII characters foobar, what is the output of the following program? 1 #include "csapp.h" 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int main() { } int fd1, fd2; char c; fd1 = Open ("foobar.txt", fd2 = Open ("foobar.txt", Read (fd2, &c, 1); Dup2
How would you use dup2 to redirect standard input to descriptor 5?
Write a program hex2dd.c that converts its 16-bit hex argument to a 16-bit network byte order and prints the result. For example linux> ./hex2dd 0x400 1024
Write a program dd2hex.c that converts its 16-bit network byte order to a 16-bit hex number and prints the result. For example, linux> ./dd2hex 1024 0x400
Figure 12.5 demonstrates a concurrent server in which the parent process creates a child process to handle each new connection request. Trace the value of the reference counter for the associated file table for Figure 12.5.Figure 12.5
Assume that a CGI program needs to send dynamic content to the client. This is typically done by making the CGI program send its content to the standard output. Explain how this content is sent to the client.
In Figure 12.43, we might be tempted to free the allocated memory block immediately after line 14 in the main thread, instead of freeing it in the peer thread. But this would be a bad idea. Why?Figure 12.43 1 #include "csapp.h" 2 #define N
In Linux systems, typing Ctrl+D indicates EOF on standard input. What happens if you type Ctrl+D to the program in Figure 12.6 while it is echoing each line of the client?Figure 12.6 1 #include "csapp.h" void echo(int connfd); 2 void command
If we were to delete line 33 of Figure12.5, which closes the connected descriptor, the code would still be correct, in the sense that there would be no memory leak. Why?Figure12.5 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include "csapp.h" void
Consider three processes with the following starting and ending times:For each pair of processes, indicate whether they run concurrently (Y) or not (N): Process A BC с Start time 1 2 4 End time 3 نيا الا 5 6
List all of the possible output sequences for the following program: 1 int main() 2 { لا لها 3 4 5 6 7 8 9 10 11 12 } if (Fork() == 0) { printf("9"); fflush(stdout); } else { printf ("0"); fflush(stdout); waitpid (-1, NULL, 0); } printf ("3"); fflush(stdout); printf ("6"); exit(0);
Consider the following program:A. How many output lines does this program generate?B. What is one possible ordering of these output lines? 1 int main() 2 { WN 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 } int status; pid_t pid; printf ("Start\n"); pid = Fork(); printf("%d\n", !pid); if (pid == 0)
Function funct3 has the following prototype:double funct3(int *ap, double b, long c, float *dp);For this function, gcc generates the following code: 1 2 3 4 لیا 5 6 7 8 9 10 11 12 13 14 15 16 17 double funct3(int *ap, double b, long c, float *dp) ap in %rdi, b in %xmmo, c in %rsi, dp in
Determine the byte encoding of the Y86-64 instruction sequence that follows. The line .pos 0x100 indicates that the starting address of the object code should be 0x100. .pos 0x100 # Start code at address 0x100 irmovq $15,%rbx rrmovq %rbx, %rcx loop: rmmovq %rcx, -3 (%rbx) addq %rbx,%rcx jmp loop
One common pattern in machine-level programs is to add a constant value to a register. With the Y86-64 instructions presented thus far, this requires first using an irmovq instruction to set a register to the constant, and then an addq instruction to add this value to the destination register.
For each byte sequence listed, determine the Y86-64 instruction sequence it encodes. If there is some invalid byte in the sequence, show the instruction sequence up to that point and indicate where the invalid value occurs. For each sequence, we show the starting address, then a colon, and then the
Write Y86-64 code to implement a recursive product function rproduct, based on the following C code:Use the same argument passing and register saving conventions as x86-64 code does. You might find it helpful to compile the C code on an x86-64 machine and then translate the instructions to Y86-64.
Modify the Y86-64 code for the sum function (Figure 4.6) to implement a function absSum that computes the sum of absolute values of an array. Use a conditional jump instruction within your inner loop.Figure 4.6 x86-64 code 1 2 3 4 5 6 7 8 9 10 11 1 2 3 5 6 7 8 9 10 11 long sun(long start, long
Modify the Y86-64 code for the sum function (Figure 4.6) to implement a function absSum that computes the sum of absolute values of an array. Use a conditional move instruction within your inner loop.Figure 4.6 x86-64 code T 2 3 4 5 6 7 8 9 10 11 1 2 3 5 6 7 8 10 long sun(long start, long
Let us determine the behavior of the instruction pushq %rsp for an x86-64 processor. We could try reading the Intel documentation on this instruction, but a simpler approach is to conduct an experiment on an actual machine. The C compiler would not normally generate this instruction, so we must use
In the server in Figure 12.8, pool.nready is reinitialized with the value obtained from the call to select. Why?Figure 12.8 1 #include "csapp.h" 2 4 5 6 7 8 9 TO 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 typedef struct { / Represents a pool of connected descriptors
In the process-based server in Figure 12.5, we observed that there is no memory leak and the code remains correct even when line 33 is deleted. In the threads based server in Figure 12.14, are there any chances of memory leak if lines 31 or 32 are deleted. Why?Figure 12.5Figure 12.14 1 #include
A. Fill each entry in the following table with “Yes” or “No” for the example program in Figure 12.15. In the first column, the notation v.t denotes an instance of variable v residing on the local stack for thread t , where t is either m (main thread), p0 (peer thread 0), or p1 (peer thread
Complete the table for the following instruction ordering of badcnt.c: Step 123 4 5 6 890 Thread 10 112NN2 7 1 Step Thread 2 1 1 2 Instr. H₁ L₁ H₂ 42 U₂ $₂ U₁ Instr. S₁ T₁ T₂ %rdx1 %rdx1 %rdx2 %rdx2 Does this ordering result in a correct value for cnt? cnt 0 cnt
Using the progress graph in Figure 12.21, classify the following trajectories as either safe or unsafe.Figure 12.21 A. H₁, L1, U₁, S1, H2, L2, U2, S2, T2, T1 B. H₂, L2, H₁, L1, U1₁, S1, T1, U2, S2, T2 C. H₁, H₂, L2, U2, S2, L₁, U₁, S₁, T1, T₂
Consider the following program, which attempts to use a pair of semaphores for mutual exclusion.A. Draw the progress graph for this program.B. Does it always deadlock?C. If so, what simple change to the initial semaphore values will eliminate the potential for deadlock?D. Draw the progress graph
A. In Figure 12.43, we eliminated the race by allocating a separate block for each integer ID. Outline a different approach that does not call the malloc or free functions.B. What are the advantages and disadvantages of this approach?Figure 12.43 1 #include "csapp.h" 2 #define N
The rand_r function in Figure 12.40 is implicitly reentrant. Explain.Figure 12.40 1 2 3 4 5 6 /* rand_r - return a pseudorandom integer on 0..32767 */ int rand_r(unsigned int *nextp) { } *nextp *nextp 1103515245+ 12345; return (unsigned int) (*nextp / 65536) % 32768;
Fill in the blanks for the parallel program in the following table. Assume strong scaling. Threads (t) Cores (p) Running time (Tp) Speedup (S₂) Efficiency (E₂) 1 1 16 1 100% 44 8 00 00 8 8 4
The solution to the first readers-writers problem in Figure 12.26 gives priority to readers, but this priority is weak in the sense that a writer leaving its critical section might restart a waiting writer instead of a waiting reader. Describe a scenario where this weak priority would allow a
Let p denote the number of producers, c the number of consumers, and n the buffer size in units of items. For each of the following scenarios, indicate whether the mutex semaphore in sbuf_insert and sbuf_remove is necessary or not. A. p= 1, c= 1, n > 1 B. p=1,c= 1, n = 1 C. p> 1,c> 1, n = 1
Showing 200 - 300
of 234
1
2
3
Step by Step Answers