Question: Using shared memory to copy a file: Write 2 programs CP 1 . c , and CP 2 . c that will use a shared
Using shared memory to copy a file:
Write programs CPc and CPc that will use a shared memory to copy data from a source file to
a destination file. The files are managed by different processes CP and CP: the source file is
managed by one process CP and the destination file is managed by another CP Assume that
the buffer used to readwrite the files is too small to contain the entire file, so that multiple read
and write calls looped are necessary to process the entire file. Find detailed requirements below.
The programs do the following:
CPc:
Creates a shared memory that will be used as a temporary buffer.
Note: All labs are due before next week's lab starts
Opens the source file, which was passed as a command line argument, to read data
from.
Reads a chunk of data from the source file and writes it to the shared memory. Waits for
CP to read the shared memory before it writes the next part of the source file to the
shared memory. The cycle continues until the file is fully copied to shared memory.
CPc:
Opens an already created shared memory that will be used as a temporary buffer.
Opens the destination file, that was passed as a command line argument, to write data
to
Reads a chunk of data from the shared memory and writes it to the destination file.
Waits for CP to write the next part of the source file before it reads it from the shared
memory and writes to the destination file. The cycle continues until the file is fully
copied and EOF is reached.
After writing is complete, detaches and deletes shared memory.
ONLY USE SYSTEM CALLS PLS
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
