Question: #include #include #include #include #include #include #include #include #include #include / / The name of the shared memory segment #define SHARED _ MEM _ NAME
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
The name of the shared memory segment
#define SHAREDMEMNAME cpscsharedmem"
The full path of the shared memory
#define FULLSHAREDMEMORYPATH devshmcpscsharedmem"
The name of the file where to save the received file
#define RECVFILENAME "filerecv"
Returns the size of the specified file
@param fileName the name of the file
@return the size of the specified or if
the file information could not be retrieved
int getFileSizeconst char fileName
The buffer to store file information
struct stat statBuff;
The file size
int fileSize ;
Get the file information
int status statfileName &statBuff;
Getting the size succeeded
ifstatus
size of file is in member buffer.stsize;
fileSize statBuff.stsize;
Something has gone wrong
else
perrorstat;
return fileSize;
The signal handler for the SIGUSR signal
that will be executed when the process receives
the SIGUSR signal. When this happens, the signal
is received, the process should get the size of the
shared memory that according to the requirnments
described in the assignment should be as big as the file,
receives the contents, and then saves them to a file
called filerecv
@param sigNum the signal number
void recvFileint signNum
The size of the shared memory
int memSize getFileSizeFULLSHAREDMEMORYPATH;
The buffer used to store the message copied
copied from the shared memory
char buff;
The total number of bytes written
int totalBytesWritten ;
The number of bytes written
int bytesWritten ;
The shared memory pointer;
void sharedMemPtr NULL;
Open the file for writing
int fd openRECVFILENAME, OCREAT OTRUNC OWRONLY;
Make sure the file was opened
iffd
perroropen;
exit;
TODO: Get the shared memory ID of the shared
memory segment allocated by the sender
Get the pointer to the shared memory.
Copy the contents of the shared memory
into the file whose name is defined by the
macro RECVFILENAME
NOTE: You will need to get the size of the
shared memory to be able to do this. You
can use the getFileSize function provided
above. The path of the file abstracting
the shared memory is defined by the
FULLSHAREDMEMORYPATH macro above.
TODO: Close the file
TODO: Deallocate the shared memory
shmunlinkSHAREDMEMNAME;
int mainint argc, char argv
TODO: Install the signal handler
for signal SIGUSR such that whenever
a process receives signal SIGUSR the
the receive function is called as a signal
handler
Wait forever until a signal arrives
whiletrue
sleep;
return ;
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
