IT LAB - 1: MINOR EXAMINATION (CS)
50 Marks (5 x 10)
I N S T R U C T I O N S
- All the code you write should be tarred and gzipped into
a single tar file named your-roll-number.tgz
-
All the output should be saved and written into a Libre
Office document named your-roll-number.odt
-
Submit both the above files either to the TA in the lab or
email to chakcs@dcis.uohyd.ernet.in with the subject
line containing the phrase IT LAB MINOR
-
Create a process P1 with two children C1 and C2. Create a pipe
from C1 to C2. C1 sends a set of 3 numbers to C2. C2 adds them and
writes the result to stdout along with the numbers in the
following format:
"C2->%d\t(%d + %d + %d)\n"
C1 again sends 3 numbers and C2 again outputs the result.
This sequence happens five times, i.e., C1 sends five sets of three
numbers. Then, C1 exits. C2 outputs the fifth result and then
it exits. Finally, P1 exits.
-
Do the same problem as above but with threads. In other
words, there is a parent process P1 which has two threads
T1 and T2 that take the functions of the two children C1 and C2
above. Be careful in setting up the pipe!
-
Write a program that creates a signal handler doubt()
for ^\ interrupt. The signal handler prints any message
of your choice and asks you to press ^\ again if you really
want to kill the process. If you press ^\ again, it kills
the process. Otherwise, the process continues to run.
-
A Seminar Room may be booked by anyone during the times
2PM - 4PM (Slot 1), 4PM - 6PM (Slot 2) and 6PM - 8PM (Slot 3)
from Monday to Friday. Bookings can be made one week in advance.
Write a program that creates four threads, each trying to book
3 Slots per week as follows: the first thread tries to book only
the 6PM - 8PM slots; the second, either 4PM - 6PM or 6PM - 8PM;
the third, only 4PM - 6PM slots; and the fourth, either 2PM - 4PM
or 4PM - 6PM slots. Make sure that the Seminar Room is allotted
to at most one thread. Output the Weekday, Slot Number and the
Thread ID for all the slots of a week.
-
Do the Problem 4 above using named semaphores. The four
threads now become independent processes and can be started in any
order in different windows. In this case, each process outputs
the slots it has been allocated and exits. Its output format is:
Process ID:\tWeekday, Slot Number