Final Exam Sample Questions

Final Exam Sample Questions

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 <stdio.h>

#include <stdlib.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <unistd.h>

#include <ctype.h>

#include <arpa/inet.h>

 

 

#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)

{

 

 

________________________ /* waiting for connection*/

 

while (read(ns, &c, 1)) {

c = toupper(c);

_______________________ /* echo back uppercase char */

}

close(ns);

}

return 0 ;

}

Client:

#include <stdio.h>

#include <stdlib.h>

#include <sys/socket.h>

#include <sys/types.h>

#include <netinet/in.h>

#include <netdb.h>

#include <string.h>

#include <unistd.h>

#include <errno.h>

#include <arpa/inet.h>

 

#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);

if(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*/ }

Academic Heros
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

Our writers are encouraged to read and research widely to have rich information before writing clients’ papers. Therefore, be it high school or PhD level paper, it will always be a well-researched work handled by experts.

Professional and Experienced Academic Writers

For one to become part of our team, thorough interview and vetting is undertaken to make sure their academic level and experience are beyond reproach, hence enabling us give our clients top quality work.

Free Unlimited Revisions

Once you have received your paper and feel that some issues have been missed, just request for revision and it will be done. In addition, you can present your work to the tutor and he/she asks for improvement/changes, we are always ready to assist.

Prompt Delivery and 100% Money-Back-Guarantee

All our papers are sent to the clients before the deadline to allow them time to review the work before presenting to the tutor. If for some reason we feel our writers cannot meet the deadline, we will contact you to ask for more time. If this is not possible, then the paid amount will be refunded.

Original & Confidential

Our writers have been trained to ensure work produced is free of plagiarism. Software to check originality are also applied. Our clients’ information is highly guarded from third parties to ensure confidentiality is maintained.

24/7 Customer Support

Our support team is available 24 hours, 7 days a week. You can reach the team via live chat, email or phone call. You can always get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

You have had a hectic day, and still need to complete your assignment, yet it is late at night. No need to panic. Place your order with us, retire to bed, and once you wake up, the paper will be ready.

Essays

Essay Writing Service

It does not matter the urgency of your paper, or the academic level, our team is ready to help you 24/7. Just contact us and all your academic needs will be sorted.

Admissions

Admission Essays & Business Writing Help

A student is often required to write an admission letter requesting to be admitted in a certain institution. For you to be gain that admission in your dream institution, you must write a convincing letter. You can depend on our team for the best admission letters.

Reviews

Editing Support

Academic writing is not just about getting information and throwing it all over. Our team will ensure you have a polished paper that is coherent and has a good flow of information. We also ensure the paper follows the correct formatting styles like APA, Harvard, MLA, Chicago/Turabian.

Reviews

Revision Support

If our writers write a paper but you are not satisfied in one way or another, you can always ask for revision. This is totally free. Our writers and editors will revise your paper untill you are be totally satisfied. We as well offer revision for papers not done by our writers at a small fee.