IMG_0148

.jpeg

School

University of Windsor *

*We aren’t endorsed by this school

Course

1

Subject

Computer Science

Date

Jan 9, 2024

Type

jpeg

Pages

1

Uploaded by DeanRat199

Report
CLsk . PP C I IS IIEOOUET. PT S WU & LT IS 1 ELCE VST $0 WEYE VT 18U j) Why does the return a new socket for each received connection? To facilitate assigning each connection to a new child, avoid using a single socket for all connections. Otherwise, one connection at a time can be replied when using a single socket. Question 3: [5 marks] (Easy) Find the problem with the /ogic of below program, assuming all system calls are successful. The problem is not about compile or run tlme errors! et " child writes 1 to 10 to the file in order like 1,2,3,...9, 1,2,3,...,9, .... However, the Kernel mj 3 Of 4 in middle of writing of a child and give it to another child. So, in the file we may end up s like 1,2,1,2,3,3,4,4,5,6, ... pipe (fd) ; for(int 1+ = 0; 1 < 10: 41){ int childpid = fork(); if (childpid == 0){ close (fd[0]); for(int j = 0; j < 10; ++j) write(fd[1], j, sizeof(int)):; exit (0); Question 4: [20 marks: 10 marks for each item] (Moderate) Find the problem with the logic of below programs, assuming all the system calls are successful. Propose fixes. The problem has nothing to do with compile or run time error. a) int childpid = fork():; if (childpid == 0) { system(cc main.c -o main); exit (0); } else if (childpid > 0) { system(./main); exit (0); } The parent process is expected to run the program after the child builds the program. But if the Kernel gives the processor to the parent first, it wants to run a program that does not exist yet! To fix, we can add in the parent before running the program m to make sure that the child finishes first. b) int server sd = socket(...); bind(server_sd, ...); listen(server sd, 5) < 0); while (1) { result = accept (server sd, ...): recv(result, client_msg ,100 , 0)) < 0); sscanf (client msg,"%s %s %d %d", user , psw, &x , &y); if ((strcmp (user, "comp2560") == 0) && (strcmp(psw, "£2022") == 0) ){ pid_t child_pid = fork(); if (child_pid == 0) add_and_send (result, x, y); } } The Server process is doing the m and then does the authentication. So, it becomes busy with the first client receiving information and cannot proceed with receiving the calls of other clients! What if the client simply do not send any info or the client is very slow?! To fix, we can ask the child to do the authentication. We can mow right after the _. Then, the Server continue with another iteration and does another not waiting for any client at all. Question 5: [20 marks] (Moderate) [Upload a File] Mohammad asks the students of his lab section to send their face/head shots. He wants to design a client-server architecture in which the students run a client program to upload their photos and the server collects the photos and save them in a folder. What would be the steps of his design in the client program and The Server program? 1) Mohammad writes The Server and runs it on his computer in the network. It accepts calls from clients. 2) Mohammad also writes a client program that a. accept a path to the photo file and Studentld as arguments to the program b. connects to The Server when it runs on a computer in the network (Because Mohammad is the programmer of the client, he knows The Server’s IP:Port to which the clients should connect!) c. sends the Studentld to the Server d. reads n bytes from the photo file and send it to The Server. e. does (d) until there is no more bytes in the photo file. Then it sends 'END’ to The Server Optionally, Mohammad can create a child in the client program to do the sending. Then the parent can report the progress to the student how many bytes have sent and how many remined so far. 3) When receiving the i-th call from a client, The Server creates i-th child 4) The i-th child receive the Studentld and create a file with the name of the Studentld S) The i-th child writes the bytes of photo file to the file as it receives them in a while loop until ‘END’ 6) When i-th child receives 'END’, closes the file, and exits. 7) The Server continues to accept calls from clients. Question 6: [10 marks] (Moderate) [Online C Compiler'?] The latest standard for C language is ISO/IEC 9899:2018, widely known as C17 and released June 2018. Hamed wanted to build his program using the latest standard, but he needed to 1) download a compiler that is C17-compliant, 2) install it on his computer, 3) build his program. He did all these steps, each of which had many challenges. Suddenly, he got the idea of exposing his installed C17-compliant compiler to all programmers for free, alleviating the three steps. What would be the steps of his design? (Hints: Lab07 + Labl1) 1) Hamed writes The Server which accepts text body of C programs from clients. 2) For each received C program, The Server creates a child 3) The child writes the C program into a file at The ?cl ver's (mnpurw named_ 4) The child builds the file using EjgeRa=ull ./main. 2in”) 5) The child returns the -pmm am file to the client Question 7: [S marks| (Easy, Cool Down
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help