Question: In C, write a program called cachememory. This program must: 1. Read 3 arguments at the command line. If there are not 3 arguments or
In C, write a program called cachememory. This program must:
1. Read 3 arguments at the command line. If there are not 3 arguments or if any arguments are invalid, the program should exit and print an error message to stderr:
a. Port, the first argument, must be an integer between 0 and 84109.
b. number_elements, the second argument, must be an integer >= 1.
c. elements_size, the third argument, must be an integer >= 1.
2. The program needs to create a listening TCP socket on the port number specified in the port argument. It should then try to accept a connection.
3. When a connection is made with the programs socket, it will spawn a child process to handle the connection and then go back to accepting connections.
4. If the parent process receives an interrupt signal (SIGINT), it should do a controlled shutdown (first, free/close any resources, wait for children to exit, and then exit).
5. When handling the connection, the child process, should:
a. Read a single line of text from the client. There are three possible formats: SET
where
-
-
b. If one of the above commands is not given, the process should write a line with "ERR INVALID_COMMAND " to the client and close the connection.
c. If a string is larger than 120 characters, the process should write a line with "ERR NAME_TOO_LONG " to the client and close the connection.
d. If a
e. If the
f. If the command was the SET command, it should read the next
i) If
ii) Otherwise, the process should write a line with "OK " to the client and close the connection.
g. If the command was the GET command, the process should write a line with "OK 1 " to the client and close the connection.
h. If the command was the DELETE command, the process should write a line with "OK 1 " to the client and close the connection.
i. If any other errors occur while the child process tries to complete a to h, it should write a line with "ERR OTHER " to the client and close the connection.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
