Operating Systems

Quiz 05

Marks: 15 (5 each)

Question 1: What are the two models of inter-processcommunication? What are the strengths and weakness of the two approaches?

Solution: The two models for IPC are:

  1. Shared-memory model.

Strength:

1. Shared memory communication is faster the message passing model when the processes are on the same machine.

Weaknesses:

1. Different processes need to ensure that they are not writing to the same location simultaneously.

2. Processes that communicate using shared memory need to address problems of memory protection and synchronization.

  1. Message-passing model.

Strength:

1. Easier to implement than the shared memory model

Weakness:

1. Communication using message passing is slower than shared memory because of the timeinvolved in connection setup

Question 2: Consider the following C code:

/*SIGPIPE generated when a computer program attempts to write to a pipe without a process connected to the other end*/

pipe(p);
signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE */
if (!fork()) {/*child*/
close(p[0]);
write(p[1], "child", 5);
}
else {/* parent */
close(p[1]);
read(p[0], &buf, 5);
}

Assuming that none of the function calls fail, what happens if the parent process is killed before the child writes to the pipe?

a / child receives SIGPIPE and terminates abnormally
b / write() returns with error
c / write() is still successful
d / a) and b)
e / None of the above

As the signal SIGPIPE is set to ignore so choice a will become invalid so choice b i.e. error is generated is the correct one

Question 3: Consider the following C code:

pipe(p);
if (!fork()) /*child*/
write(p[1], "child", 5);
else /* parent */
read(p[0], &buf, 5);

Assuming that none of the function calls fail, what happens if the parent process is killed before the child writes to the pipe?

a / child receives SIGPIPE and terminates abnormally
b / write() returns with error
c / write() is still successful
d / a) and b)
e / None of the above

It is still successful because the other reading end of the child fd is still alive so write will be successful.