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 2 programs CP1.c, and CP2.c that will use a shared memory to copy data from a source file to
a destination file. The 2 files are managed by different processes (CP1 and CP2): the source file is
managed by one process (CP1) and the destination file is managed by another (CP2). Assume that
the buffer used to read/write 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:
CP1.c:
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
CP2 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.
CP2.c:
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 CP1 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**
Using shared memory to copy a file: Write 2

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 Accounting Questions!