Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part I: Shared Memory The sender and the receiver programs will work as follows: The Receiver: 1 . The receiver shall be started before the
Part I: Shared Memory
The sender and the receiver programs will work as follows:
The Receiver:
The receiver shall be started before the sender It shall be invoked as recv from the
command line.
When launched, it shall override the default signal handler function for the SIGUSR signal the signal reserved for custom uses by user programs with a function called void
recvFileint sigNum After doing so the program shall go into a sleeping loop where
it will sleep until a SIGUSR signal arrives.
Once the SIGUSR signal arrives, the program shall invoke the recvFile function. The
function shall perform the following operations:
a Get the shared memory ID for the shared memory segment named cpscsharedmem.
If the segment does not exist, the receiver exits with an error Missing shared
memory segment!". Otherwise, if the segment exists, the receiver continues to the
next step.
b The receiver should assume that the shared memory segment in the previous step
contains the data from a file that was put there by the sender The receiver shall
then get the size of the shared memory segment, read the data from the entire memory
segment, and write the read data to a file called file recv.
c Finally, the receiver shall deallocate the shared memory segment and exit.
The Sender:
The sender shall be started as sender
For example, sender file.txt The first argument represents the name of the
file to send and the second represents the process ID of the receiver process. Please note:
you can always get the process id of the receiver process using the pidof command. Eg
pidof recv. Ofcourse this assumes that the receiver is already running.
The sender shall then allocate a shared memory segment named cpscsharedmem with
permissions of This is done to ensure that only the processes running with the UID of
the current user can access the shared memory contents important security consideration
to ensure that processes from other users cannot spy on the current user through shared
memory.
The sender shall then get the size of the file whose name was provided in the command
line, set the size of the shared memory to the size of the file, and shall then read the
contents of the file and write them to the shared memory segment.
Finally, the sender program shall send the SIGUSR signal to the receiver program that
the sender will assume is running. The sender can do this by invoking the kill system
call used for sending signals as killSIGUSR The second
argument is the process id of the receiver the user has provided at the command line
NOTE: you will need to convert the pid at the command line from string into integer.
That can be done using the atoi function. Eg int pid atoiargv
The highlevel skeletons for the sender and receiver can be found in the skeletonssharedmem
Some of the command line argument parsing has already been done for you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started