CS604 Operating Systems Assignment 2 Solution Spring 2014

Question No.1: [Marks 5]
Consider a scenario of post mailbox, there are two processes named sender S and receiver R. Both processes can communicate with each other by name along with message. You need to Identify what type of IPC is this?
Write the send and receive primitives for stated processes.
Identify at least three properties of communication channel or link in this scheme.


Indirect communications :
messages sent to and received from mailboxes (or ports)
mailboxes can be viewed as objects into which messages placed by processes and from which messages can be removed by other processes each mailbox has a unique ID two processes can communicate only if they have a shared mailbox
send ( A, message ) : send a message to mailbox A
receive ( A, message ) : receive a message from mailbox A

a communications link is only established between a pair of processes if they have a shared mailbox
a pair of processes can communicate via several different mailboxes if desired
a link can be either unidirectional or bidirectional
a link may be associated with more than two processes
allows one-to-many, many-to-one, many-to-many communications
one-to-many : any of several processes may receive from the mailbox
e.g. a broadcast of some sort

Question No.2: [Marks 5]
Considering the performance of FCFS scheduling algorithm for three CPU bound processes, calculate the followings, If process P1 takes 19 seconds, P2 takes 23 seconds and P3 takes 8 seconds and processes arrive in order P1, P2 and P3:
a) Turnaround Time per process
b) Average Turnaround time of processes
c) Average waiting time of processes and identify either convey effect occurs or not.


  • Turnaround Time? (19 + 23 + 8) = 50 second
  • Average Turnaround time of processes = 50/3 = 16.66 sec
  • Average waiting time = (0+19+42)/3
    =20.3 second

Question No.3: [Marks 10]
Using C programming language, write a program that uses the pthread library to create two threads and display certain messages. Messages must have following words and sequence:
First thread in process: My VU student ID is BC123456
Thread created
Second thread is in process: My Subject Code is CS604
Thread Created
(code:4 marks, compile and execute command on Ubuntu:2 marks and correct output:4 marks)


#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/* Prototype for a function to be passed to our thread */
void* MyThreadFunc(void *arg);
int main()
pthread_t aThread;

pthread_t aThread2;
/* Create a thread and have it run the MyThreadFunction */
pthread_create(&aThread, NULL, MyThreadFunc, NULL);

pthread_create(&aThread2, NULL, MyThreadFunc, NULL);
/* Parent waits for the aThread thread to exit */
pthread_join(aThread, NULL);

pthread_join(aThread2, NULL);
printf (“Exiting the main function.\n”);
return 0;
void* MyThreadFunc(void* arg)
printf (“Hello, world! … The threaded version.\n”);
return NULL;