Question: Write a C program that does the following: Runs two processes, parent P0 and child P1. P0 creates a pipe. P0 writes to the pipe

Write a C program that does the following:

Runs two processes, parent P0 and child P1.

P0 creates a pipe.

P0 writes to the pipe and P1 reads from the pipe.

Each process creates two threads running function thread0() in P0 and thread1()

in P1. Threads must be allowed to run with maximum concurrency - but correctly.

Each thread has its own ID, which is an integer.

Process P0 opens a file for reading.

Each thread in P0 reads 512 bytes from the file, calls function proc0() which

processes the data and returns a result of a single integer value. The thread then

writes into the pipe its own ID followed by the proc0() result with two calls to

write().

Integers are 8 bytes, so writing the result into the pipe could use

write(pipedescriptor, (char *)&result,8)

Each thread in P1 reads two integer values from the pipe, the thread ID and the

data value produced by the thread calling proc0() on the P0 side, calls function

proc1() which processes the data and returns a result of a single integer value.

The thread then stores the result value in the next available element of an

integer array data[]. The thread needs to use and increment variable indx.

Array data[] is created by P1 using malloc() before any threads are created. It

has some finite size, DSIZE. P1 also creates an integer variable called indx

(initialized to 0) that has the index of the location in data[] where the next value

will be stored by one of the threads in P1.

Process P1, when the array data[] becomes full,

sends signal SIGUSR1 to process P0

The SIGUSR1 default action is Terminate (so P1 must catch it)

tells its own threads to terminate

performs clean-up

terminates

Process P0, when it receives the signal sent from P1

notifies its own threads that they should finish the current operation and

terminate

performs clean-up

waits for P1 to terminate

terminates

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!