If we were to delete line 33 of Figure12.5, which closes the connected descriptor, the code would
Question:
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
Transcribed Image Text:
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 echo(int connfd);
void sigchld_handler (int sig)
{
}
while (waitpid (-1, 0, WNOHANG) > 0)
;
return;
int main(int argc, char **argv)
{
}
int listenfd, connfd;
socklen_t clientlen;
struct sockaddr_storage clientaddr;
if (argc ! 2) {
fprintf(stderr, "usage: %s
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 echo(int connfd);
void sigchld_handler (int sig)
{
}
while (waitpid (-1, 0, WNOHANG) > 0)
;
return;
int main(int argc, char **argv)
{
}
int listenfd, connfd;
socklen_t clientlen;
struct sockaddr_storage clientaddr;
if (argc ! 2) {
fprintf(stderr, "usage: %s \n", argv[0]);
exit(0);
}
Signal (SIGCHLD, sigchld_handler);
listenfd =
Open_listenfd (argv[1]);
while (1) {
clientlen sizeof (struct sockaddr_storage);
}|
connfd = Accept (listenfd, (SA) &clientaddr, &clientlen);
== 0) {
if (Fork ()
Close (listenfd); /* Child closes its listening socket */
echo (connfd);
/* Child services client */
Close (connfd);
/* Child closes connection with client */
/* Child exits */
exit(0);
==
}
Close (connfd); /* Parent closes connected socket (important!) */
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 37% (8 reviews)
When a process terminates for any rea...View the full answer
Answered By
Chiranjib Thakur
I have no tutoring experience yet, but I can share my skills and knowledge gained from my education and work experiences. I have been a CPA since 2012 with 6 years of work experience in internal auditing and 4 years of work experience in accounting at the supervisory level.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Computer Systems A Programmers Perspective
ISBN: 9781292101767
3rd Global Edition
Authors: Randal E. Bryant, David R. O'Hallaron
Question Posted:
Students also viewed these Computer science questions
-
The Eastclock Corporation (EC) manufactures timing devices that are used in industrial settings. Recently, profits have fallen, and management is seeking your advice as an outside consultant on...
-
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...
-
If we were to look at two new plant locations, where would they be? (See JPMS.zip on the book Web site for the model and more information.) 2. If we were to look at two new plant locations, where...
-
Describe a procedure for solving a first-degree inequality.
-
The Haverly Company expects to finish the current year with the following financial results, and is developing its annual plan for next year. The following facts are available. FACTS Payables are...
-
Kitchen Supply, Inc. (KSI), manufactures three types of flatware: institutional, standard, and silver. It applies all indirect costs according to a predetermined rate based on direct labor-hours. A...
-
How does inflation distort ratio analysis comparisons, both for one company over time (trend analysis) and when different companies are compared? Are only balance sheet items or both balance sheet...
-
Faircloth Financial specializes in home equity loans, loans that customers can take out against the equity they have in their homes. ("Equity" represents the difference between the home's value and...
-
Question 4: (6 marks) 1. Discuss the interplay between sustainability reporting, accountability relationships and stakeholders. 2. Discuss the role sustainability reporting plays in the potential...
-
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...
-
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...
-
What did the chief benefit of the early Internet prove to be?
-
By uploading this work, I attest that the work contained herein is solely my own, that I only used the given equation sheet as a reference, and that I have not received any information from anyone...
-
Demand for patient surgery at Washington General Hospital has increased steadily in the past few years, as seen in the following table: ...
-
Explain product analysis
-
The accountant at EZ Toys, Inc. is analyzing the production and cost data for its Trucks Division. For October, the actual results and the master budget data are presented below. Actual Results:...
-
2. 2D Design (4 points): The Pawnee Department of Parks and Recreation has received alarming reports that their picnic tables might be unstable. Examine the picnic table design below (which weighs 50...
-
A mixture of gases at 40 8C and 400 kPa is contained in a cylinder with an initial volume of 0.2 m3. The mixture contains 2 kg of CO2 and 4 kg of air. The pressure is reduced during an isothermal...
-
Parkin Industries, a U.S. company, acquired a wholly-owned subsidiary, located in Italy, at the beginning of the current year, for 200,000. The subsidiary's functional currency is the euro. The...
-
Write down the binary representation of the decimal number 63.25 assuming it was stored using the single precision IBM format (base 16, instead of base 2, with 7 bits of exponent).
-
Write down the binary bit pattern to represent -1.5625 10 -1 assuming a format similar to that employed by the DEC PDP-8 (the left most 12 bits are the exponent stored as a twos complement number,...
-
IEEE 754-2008 contains a half precision that is only 16 bits wide. The left most bit is still the sign bit, the exponent is 5 bits wide and has a bias of 15, and the mantissa is 10 bits long. A...
-
17. Winedark Sea Ltd sells prints of classic paintings. The prints are done on expensive paper and are quite costly. Pricing the prints to sell is hard because the popularity of a print is difficult...
-
plz be clear and specific with answer Sweeten Company had no jobs in progress at the beginning of March and no beginning inventories. The company has two manufacturing departments --Molding and...
-
The following T account balances are taken from Forester Corp. Manufacturing Overhead Work in Process 370,000 366,000 90,000 Finished Goods Cost of Goods Sold 75,000 450,000 Required: Prepare the...
Study smarter with the SolutionInn App