Answered step by step
Verified Expert Solution
Link Copied!

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:
1. The receiver shall be started before the sender. It shall be invoked as ./recv from the
command line.
2. When launched, it shall override the default signal handler function for the SIGUSR1 signal (the signal reserved for custom uses by user programs) with a function called void
recvFile(int sigNum). After doing so, the program shall go into a sleeping loop where
it will sleep until a SIGUSR1 signal arrives.
3. Once the SIGUSR1 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 cpsc351sharedmem.
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:
1. The sender shall be started as ./sender .
For example, ./sender file.txt 1245. 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. E.g.,
pidof recv. Ofcourse, this assumes that the receiver is already running.
2. The sender shall then allocate a shared memory segment named cpsc351sharedmem with
permissions of 0600. 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.
3. 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.
4. Finally, the sender program shall send the SIGUSR1 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 kill(SIGUSR1,). 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. E.g., int pid = atoi(argv[2]).
The high-level skeletons for the sender and receiver can be found in the skeletons/sharedmem.
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions