CS6233 – Spring 2025
Midterm Exam - Programming Problem (10 points)
Time Allowed: 60 minutes
This problem is open book, notes, class page, man pages, etc.
You must work alone and may not consult or seek help from others (persons or bots); locally,
remotely, via internet forums, etc.
You may perform your work on a Linux virtual machine, a Linux laptop, or a piece of paper that
you later submit to a proctor.
If you wish to leave early, you MUST check out with a proctor before exiting the exam room.
Once you check out and leave the room, you may not submit anything afterwards (you will get a
zero if you do!)
Programming problem:
Write a program whose main routine obtains two parameter n and d from the user (i.e.,
passed to your program when it was invoked from the shell, n>1). The main routine of your
program shall create two ordinary pipes and then spawns a child process using the fork()
system call.
The child process waits for a random amount of time between 0 and 5 seconds, then sends a
single character ‘R’ to the parent via the first pipe, indicating that it is ready to receive data.
The parent waits for that single character (‘R’) and responds by creating and sending an
arithmetic sequence to the child via the second pipe, one element at a time, waiting for a
random amount of time (0 to 5 seconds) between transmitting elements.
The transmitted sequence is of length n and elements of type int, such that each element has a
value of kd, where k is the element number (0 to n-1). For example, if n=5 and d=2, the
sequence shall be 0,2,4,6 and 8.
When the child receives an element, it prints it immediately to the standard output. After the
child receives and prints the entire sequence, it exits.
After the child exits, the parent closes the pipes and exits.
Notes: You may seed your random number generator using:
srand(time(NULL) + getpid());
You may then use the random generator to generator a random number:
rand().
What to submit to Gradescope: Only submit your c file. No screen shots.