2018/9/25 Quiz 6 | COMP1521 18s2 | WebCMS3
https://webcms3.cse.unsw.edu.au/COMP1521/18s2/activities/quizzes/1213 1/3
Quiz 6
1.
Which of the following best describes how clients interact with servers in a socket-based client-server
system?
the client sends requests to the IP address of the server
the client connects to the server, which returns a socket descriptor
the client connects to the server, which sends a request key
the client receives responses from the server on a VPN connection
none of the other options is correct
2.
Which of the following best describes what the bind() function does?
fixes the physical location of a socket
connects one socket descriptor to another, to start a session
blocks the calling process until a network connection is available
associates a network address with an open socket descriptor
none of the other options is correct
2018/9/25 Quiz 6 | COMP1521 18s2 | WebCMS3
https://webcms3.cse.unsw.edu.au/COMP1521/18s2/activities/quizzes/1213 2/3
3.
What problem exists in the following code to implement a shared buffer with N slots?
sem_t mutex; sem_init(&mutex, 1);
sem_t nfree; sem_init(&nfree, N);
Item buf[N];
void producer() {
Item it = generateItem();
while (1) {
sem_wait(&nfree); sem_wait(&mutex);
addItemToBuffer(it, buf);
sem_post(&mutex);
}
}
void consumer() {
Item it;
while (1) {
sem_wait(&mutex);
it = getItemFromBuffer(buf);
sem_post(&mutex); sem_post(&nfree);
consumeItem(it);
}
}
Assume that functions like addItemToBuffer() and getItemFromBuffer() correctly implement a circular
buffer of size N.
the producer and consumer can be deadlocked
the producer can add items into a full buffer
the consumer can take items from an empty buffer
mutually exclusive access to the buffer is not enforced
none of the other options is correct
2018/9/25 Quiz 6 | COMP1521 18s2 | WebCMS3
https://webcms3.cse.unsw.edu.au/COMP1521/18s2/activities/quizzes/1213 3/3
4.
Which of the shell command pipelines below is equivalent to the following program?
int main()
{
FILE *fp, *pp; char line[100];
fp = fopen(“file1″,”r”);
assert(fp != NULL);
pp = popen(“wc -l”,”w”);
assert(pp != NULL);
while (fgets(line,100,fp) != NULL)
fputs(line,pp);
fclose(fp); pclose(pp);
}
Assume that all of the appropriate #includes have been done.
wc -l `fopen file1`
cat file1 | wc -l
ls -l file1
wc -l | cat file1
none of the other options is correct
Submit