Computing Lab Lab Test 2
Computing Lab Lab Test 2
Submission instructions:
Please upload a zip file with the name <rollno>_computing-lab-test2.zip
containing all the relevant files with correct names (specific filenames are
mentioned in each question)
_____________________________________________________________________________________________________
Simulate three booking counters using semaphore. Once a thread gets hold of a booking counter,
it will book the number of tickets requested (if a CP thread wants more than 2 tickets give at max
2 tickets, if a VIP thread want more than 5 tickets, give at max 5 tickets) or failing that (if there are
not enough tickets) book the tickets available, then the thread will exit. If a VIP thread is waiting at
a booking counter it will get priority over all waiting CP threads. After booking tickets a thread will
exit. Once all threads exit, output the following in the main thread and exit: “VIP threads booked
XXX tickets in YYY time” and “CP threads booked XXX tickets in YYY time”. XXX is the total number
of tickets booked and YYY is the total time taken from start to finish of each thread.
double **A;
double **B;
double **C;
int veclen, i, j;
} ProcessData;
// veclen: () /+,
// i, j: cell to compute
In this part you should simply create !" ∗ %& child processes each for computing each element.
Note that no mutual exclusion is needed as all the output entries are created independently and
all the inputs are already available.
Question 3 (5 + 5 + 5 + 10 = 25 marks)
3.1. Write a shell code segment which can read strings like “2 x 3” as argument and output the
multiplication of those two numbers (e.g., 2 and 3) in the terminal. Write your code in
“<rollno>_Q3.1.bash” file.
3.2. You have three files 1.txt, 2.txt, 3.txt. Each file contains three space separated columns and
each column contains non-negative numbers. Write a shell code segment to compute and print
the average and standard deviation of each of these columns over all the files. Write your code in
“<rollno>_Q3.2.bash” file.
3.3. Assume you have a file where one string (without space) is contained in each line of the file.
Each string is “Peter”, “Paul” or “Mary”. Write a shell code segment to compute the frequency of
occurrences for the strings “Peter”, “Paul” and “Mary”. Write your code in “<rollno>_Q3.3.bash”
file.
3.4. Write a C/C++ code which when you press ctrl+c once, goes to sleep and when you press
ctrl +c again , wakes up and waits for next ctrl +c. The “sigsuspend” call might be useful.
Write your code in “<rollno>_Q3.4.c” or “<rollno>_Q3.2.cpp” fille.