ECSE 427程序 辅导、 写作Systems课程程序、C++程序

” ECSE 427程序 辅导、 写作Systems课程程序、C++程序ECSE 427/COMP 310 Operating Systems Assignment 01 Simple RPC ServiceFall 2020 (version 2) Page 1 9/21/2020Simple Remote Procedure Call ServiceCheck My Courses for Due DateHigh-Level DescriptionConsider a simple calculator. It has a read-eval-print-loop (REPL), where you enter something likethe following.The calculator is structured as two programs: frontend and backend. The frontend does not do theactual calculations. It just prints the prompt, get the input from the user, parses the input into amessage. The frontend passes The message to the backend that does the actual calculations andpasses the result back to the frontend, where it is printed to the user. We write two programsbackend.c and frontend.c. The backend has some functions it wants to expose for the frontend.The frontend needs to call those functions that are exposed by the backend. The remote procedurecall service (RPCServ) is responsible for linking the two. You are expected to develop such aRPCServ as part of this assignment. We start with a very simple implementation. The frontendissues an execution command and backend runs it and returns the result. This simple structurewould work even with multiple frontends if the commands issued by the frontends can be executedvery quickly. If some commands can hold the backend for a long time (like seconds), we have aproblem. When a frontend is running a long command, other frontends will find the backendunavailable. That is, you run sleep 5 in the frontend and the backend is held by that frontend for 5seconds. If other frontends try to run a calculation, they will not get any results. To solve thisproblem, you will use multi-processing. That is the backend will create a serving process for eachfrontend. In this configuration, as soon as the frontend connects to the backend, we create a newserving process that is dedicated to the frontend and let it serve the frontends requests. Even if thefrontend does a sleep 5, it would not cause problems for other frontends. The backend is stillavailable for requests from other frontends. To keep things simple, we limit the number ofconcurrent frontends to 5.Frontend RequirementsECSE 427作业 辅导、 写作Systems课程作业The pseudo code shown below for the frontend is not complete. It shows the bare essentials. Youneed to add the missing functions to make the frontend meet all the requirements and make it workwith RPCServ and the backend.backend = RPC_Connect(backendIP, backendPort)while(no_exit) {print_prompt()line = read_line()ECSE 427/COMP 310 Operating Systems Assignment 01 Simple RPC ServiceFall 2020 (version 2) Page 2 9/21/2020cmd = parse_line(line)RPC_Call(backend, cmd.name, cmd.args)}RPC_Close(backend)The frontend does not implement any of the commands the user enters into the shell. It simplyrelays them to the backend. You will notice that the command entered by the user looks like thefollowing: command (string) and parameters. We will restrict the parameters to 2 or less. You canhave commands with No parameters. The parameters can be integers or floating-point numbers.You need to have an RPCServ interface to send the command and parameters to the backend. Inthe pseudo code, we show such an interface RPC_Call(). The frontend will check if the userhas entered the exit command. If that is the case, the frontend will stop reading the next commandand terminate the association with the backend. The backend is a separate process, so it keepsrunning even after the frontend has stopped running. The user can enter the shutdown commandin the frontend to terminate the backend. With multiple frontends connecting to the backend, theshutdown can be tricky. More on this in the backend requirements. Some commands entered bythe user in the frontend may not be recognized by the backend, in that case the backend will sendthe NOT_FOUND error message. The front needs to display this to the user. We can also haveerror message for certain operations such as division by zero errors. These error messages need tobe displayed as well.Backend RequirementsThe pseudo code shown below for the backend is not complete. It shows the bare essentials. Youneed to add the missing functions to make the backend meet all the requirements and make it workwith RPCServ and the frontend.serv = RPC_Init(myIP, myPort)for_all_functions(name)RPC_Register(serv, name, function)while(no_shutdown) {client = accept_on_server_socket(serv)serv_client(client)}The backend sets up a Server at myPort in the current machine (you can use 127.0.0.1 to pointto the current machine). The server should be set up, so it is bound to the given port and is listeningfor incoming connections from the frontend. Before you start accepting the connections, you needto register all the functions that the RPCServ is willing to offer as a service. For example, if youhave the following function to add two integers that you want to expose, you need to register itwith the RPCServ as shown below.int addInts(int x, int y) {return x + y;}ECSE 427/COMP 310 Operating Systems Assignment 01 Simple RPC ServiceFall 2020 (version 2) Page 3 9/21/2020RPC_Register(add, addInts)The RPCServ is responsible for invoking (that is calling) the addInts function with theappropriate parameters when a request comes from the frontend.The RPCServ keeps running until a shutdown command is issued by the frontend. With a singlefrontend, this is quite simple. You simply exit the program after closing the sockets in an orderlymanner. With multiple frontends, things can get little bit tricky.With multiple frontends, the pseudo code shown above needs some revision. Soon after acceptinga connection, you need to create a child process and let that child process handle the newconnection. That is the socket connection (client) is passed to the child process and it will be doingthe calculations and Sending the results or error back to the client. The server is free to loop backand accept another connection without waiting for the previous frontends service to complete.With multiple frontends, lets consider the situation where the backend received the shutdowncommand. The command is received in a child process. For the backend to terminate, we mustterminate the parent process that started running the backend. The child that received the shutdownmust notify the parent about the reception of the shutdown. For this purpose, the child can use thereturn value in an exit() system call. The parents gets the return value of the child using thewaitpid() system call. The example code below shows how you can return a value from a childto parent.#include stdio.h#include unistd.h#include sys/types.h#include sys/wait.hint main() {int pid;int rval;if ((pid = fork()) == 0) {sleep(10);return 10;}while (1) {sleep(1);int res = waitpid(pid, rval, WNOHANG);printf(Returned value %d\n, WEXITSTATUS(rval));}}On the server socket, The parent is going to block. It is waiting for new connections from thefrontends. Once a connection comes in, the parent is going to unblock and proceed to create a childprocess to handle the frontend. To handle the shutdown properly, we need to check whether anychild processes have already issued a shutdown. If so, we close the client connection that justarrived and stop accepting any more connections. When all the child processes that are runninghave completed their execution, the parent terminates. Because the parent is blocking on the serversocket, it would not be able to shutdown or even know about the shutdown when it arrives. TheECSE 427/COMP 310 Operating Systems Assignment 01 Simple RPC ServiceFall 2020 (version 2) Page 4 9/21/2020parent would only detect the shutdown at the arrival of the next frontend processing request.Therefore, the backend would keep going even after shutdown has been sent until the next frontendrequest.NOTE: There is a better way of doing the same activity as the above that will use epoll() or select().If you are following the advanced tutorials and are already familiar with C/Linux socketprogramming, you are strongly encouraged to use those system calls. The design is left to you, butyour design needs to meet or exceed the above functionality. For example, with epoll() or select()you could terminate the Backend without waiting until the next frontend request.Backend Functions: You need to provide the following functions in the backend implementation.1. int addInts(int a, int b);// add two integers2. int multiplyInts(int a, int b);// multiple two integers3. float divideFloats(float a, float b);// divide float numbers (report divide by zero error)4. int sleep(int x);// make the calculator sleep for x seconds this is blocking5. uint64_t factorial(int x);// return factorial xRPCServ RequirementsWe are not going to test your RPCServ implementation with applications other than the calculator.Therefore, we are not standardizing on the RPCServ interface. However, you are stronglyencouraged to provide at least the following.rpc_t *RPC_Init(char *host, int port)// rpc_t is a type defined by you and it holds// all necessary state, config about the RPC connectionRPC_Register(rpc_t *r, char *name, callback_t fn)// callback_t is type defined by yourpc_t *RPC_Connect(char *name, int port)RPC_Close(rpc_t *r)RPC_Call(rpc_t *r, char *name, args..)// You can have Different variations to// handle different number of parameters and typesThis is a guide for you to organize the RPCServ implementation. You can change the functionsignatures and have more functions in your RPCServ implementation.How the Assignment Will be Graded?ECSE 427/COMP 310 Operating Systems Assignment 01 Simple RPC ServiceFall 2020 (version 2) Page 5 9/21/2020We will use a shell script to grade your assignment. The shell script will start the backend and startthe frontend and inject Different inputs. The script checks the output from your frontend against anexpected value and reports an error.Grade distribution will be notified very soon by the TAs.What You Need to Handin?What needs to be handed in?Source files, Makefile or CMakeLists.txt?Can I Collaborate with My Friends?This is an individual Assignment. You can brainstorm with your friends in developing RPCServand other components. The final implementation must be yours only. You cannot do group coding.如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导