CS 288 Final Exam Sample Questions NOTE: The questions are for you to understand in which way the above contents will be tested. However, they do not indicate the coverage of the test. PART 1....

CS 288 Final Exam Sample Questions
NOTE:
The questions are for you to understand in which way the above contents will be tested. However, they do
not indicate the coverage of the test.

PART 1. True/False Questions
____1. In Linux, kill command and ​kill()​ system call are only used to kill processes.

____2. Only a process with elevated privilege can use a port number below 1024.

____3. Only when processes are running on the same computer, can they communicate using sockets.

____4. When two processes communicate using sockets and TCP, the socket used to make a connection
and the socket used to transfer data are different sockets.

____5. When used to create a socket, the port number and IP address must be in network order.

____6. When developing a web server, the program can send the HTTP header and HTTP body together
in one send or write call.

____7. In an MPI program, process ​A​ can send a pointer to another process ​B​, so that process ​B​ can
access data with the pointer.
____ ​8. In Linux, a program can call the stat() function to get the current status of the caller process.
____ ​9. In a program with multiple threads, a thread cannot access the memory malloc()-ed by another
thread.
PART 2. Fill-in-the-Blank Questions and Short Questions
1~3. Assume that a linked list is to be built with the nodes defined as follows:
struct listNode{
int data;
struct listNode *nextPtr;
};
Two pointers ​head​ and ​cursor​ are defined as
struct listNode *head=NULL, *cursor;
1. Write the code to ​create​ the first node, which contains a number 5, and ​add​ to the list. After the
execution of the code, the ​head​ should point to the first node.
________________________________________________________________
2. Write the code to ​create​ another node, which contains a number 3, and ​add​ at the ​beginning​ of the list.
After the execution of the code, the ​head​ should point to this new node.
________________________________________________________________
3. Write the expression to determine whether the pointer ​cursor​ points to the LAST node of the list is
______________________________________________
4. In a C program, ​kill(getppid(), SIGKILL)​ is to ​_____________________​.
5~12. The following two programs implement a server and a client, respectively. The server takes a
message from a client, turns all characters into uppercase, and echoes the message back to the client. The
programs use sockets with TCP protocol. The server does not take any arguments. But the client needs
two arguments in the command line: the IP address of the server (argv[1]) and the message itself
(argv[2]).
From the following lines of code, choose the line of code that best completes the functionality of the
program. Note that it may be necessary to use one line multiple times. Choose option ZZ if no code is
needed. Please enter the letter corresponding to your answers on the lines provided below.
Server:
#include
#include
#include
#include
#include
#include
#include
#define thePort 5000
int main()
{
int soc, ns, result ;
struct sockaddr_in self;
char c ;
/* create a socket */
_____________________________________
self.sin_family = AF_INET;
self.sin_addr.s_addr = htonl(INADDR_ANY);
self.sin_port = htons(thePort);
____________________________________
listen(soc, 1);
while(1)
{
XXXXXXXXXX________________________ /* waiting for connection*/
while (read(ns, &c, 1)) {
XXXXXXXXXXc = toupper(c);
XXXXXXXXXX_______________________ /* echo back uppercase char */
}
XXXXXXXXXXclose(ns);
}
return 0 ;
}
Client:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define thePort 5000
int main(int argc, char *argv[])
{
int soc, len, result;
char c;
struct sockaddr_in serv_addr;
/* create a socket */
_____________________________________
/* connect to the server */
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(thePort);
_______________________________________
_______________________________________
/* send and receive message */
_______________________________________
do {
result=read(soc, &c, 1);
XXXXXXXXXXif(result > 0){
len-=result;
write(1, &c, 1);
}
}while(len>0);
write(1, "\n", 1);
return 0;
}
A. soc = socket(AF_INET, SOCK_DGRAM, 0);
B. bind(soc, (struct sockaddr *)&self, sizeof(self));
C. soc = socket(AF_INET, SOCK_STREAM, 0);
D. send(ns, &c, 1);
E. write(ns, c, 1);
F. inet_pton(AF_INET, argv[1], &serv_addr.sin_addr);
G. ns = accept(soc, NULL, NULL);
H. write(ns, &c, 1);
I. send(soc, argv[2], len);
J. connect(soc,(structsockaddr*)&serv_addr,sizeof(serv_addr));
K. write(soc, argv[2], len);
L. strcpy(serv_addr.sin_addr, argv[1]);
ZZ. /* No code needed on this line */
13. ​If you were asked to write a program that generates either ​multiple threads OR multiple
processes​ to solve a 15 puzzle problem, such that solutions can be obtained more quickly, what
do you choose, multiple threads or multiple processes? ​Explain your choice​.
PART 3. Programming Questions
Write a C function that takes a linked list and a number and performs the following task. The
function scans the linked list for a node saving the same number; if such node is found, the
function removes the node; if such node is not found, the function inserts a new node to the
linked list and saves the number into the new node. Each node is defined as
struct node {
int num;
struct node * next;
};

The numbers saved in the linked list are sorted in ascending order. When a new node is inserted,
the order should also be kept.

void check_list (struct node * list, int mynum){
/* YOUR CODE STARTS HERE*/
}
May 07, 2021

Submit New Assignment

Copy and Paste Your Assignment Here