Question: Programming Assignment This assignment has the following goals: To solidify your understanding of IPC principles . To develop greater appreciation for the different IPC mechanisms

 Programming Assignment This assignment has the following goals: To solidify your

Programming Assignment

This assignment has the following goals:

To solidify your understanding of IPC principles.

To develop greater appreciation for the different IPC mechanisms.

To gain hands-on experience using shared memory.

To gain hands-on experience using message queues.

To gain hands-on experience using signals.

To learn how to combine shared memory and message queues in order to

implement a practical application where the sender process sends information to the receiver process.

Overview

In this assignment you will use your knowledge of shared memory and message queues in order to implement an application which synchronously transfers files between twoprocesses.

You shall implement two related programs: a sender program and the receiver program asdescribed below:

sender: this program shall implement the process that sends files to the receiver process.It shall perform the following sequence of steps:

Thesendershallbeinvokedas./sender file.txtwheresenderisthenameofthe executable and file.txt is the name of the file to transfer.

The program shall then attach to the shared memory segment, and connect to the message queue both previously set up by the receiver.

Read a predefined number of bytes from the specified file, and store these bytes in the chunk of shared memory.

Send a message to the receiver (using a message queue). The message shall contain a field called size indicating how many bytes were read from the file.

Wait on the message queue to receive a message from the receiver confirming success-ful reception and saving of data to the file by the receiver.

Go back to step 3. Repeat until the whole file has been read.

When the end of the file is reached, send a message to the receiver with the size

field set to 0. This will signal to the receiver that the sender will send no more.

Close the file, detach shared memory, and exit.

receiver: this program shall implement the process that receives files from the senderprocess. It shall perform the following sequence of steps:

The program shall be invoked as ./recv where recv is the name of the executable.

The program shall setup a chunk of shared memory and a message queue.

The program shall wait on a message queue to receive a message from the sender

program. When the message is received, the message shall contain a field called size denoting the number of bytes the sender has saved in the shared memory chunk.

If size is not 0, then the receiver reads size number of bytes from shared memory, saves them to the file (always called recvfile), sends message to the sender acknowl- edging successful reception and saving of data, and finally goes back to step 3.

Otherwise, if size field is 0, then the program closes the file, detaches the shared memory, deallocates shared memory and message queues, and exits.

When user presses Control-C in order to terminate the receiver, the receiver shall de- allocate memory and the message queue and then exit. This can be implemented by setting up a signal handler for the SIGINT signal. Sample file illustrating how to do this have been provided (signaldemo.cpp).

Technical Details

The skeleton codes for sender and receiver can be found. The files are asfollows:

sender.cpp: the skeleton code for the sender (see the TODO: comments in order to find out what to fill in)

recv.cpp: the skeleton code for the receiver (see the TODO: comments in order to find out what to fill in).

msg.h: the header file used by both the sender and the receiver It contains the struct of the message relayed through message queues). The struct

contains two fields:

long mtype: represents the message type.

int size: the number of bytes written to the shared memory. In addition to the structure, msg.h defines macros representing two different messagetypes:

SENDER_DATA_TYPE: macro representing the message sent from sender to receiver. Its type is 1.

RECV_DONE_TYPE: macro representing the message sent from receiver to the sender acknowledging successful reception and saving of data.

NOTE: both message types have the same structure. The difference is how themtype field is set. Also, the messages of type RECV_DONE_TYPE do not make use of the size field.

Makefile: enables you to build both sender and receiver by simply typing make at the command line.

signaldemo.cpp: a program illustrating how to install a signal handler for SIGSTPsignal sent to the process when user presses Control-C.

Please note: by default the skeleton programs will give you errors when you run them. This is because they are accessing unallocated, unattached regions of shared memory. Its your job to fill in the appropriate functionality in the skeleton, de-noted by the TODO comments, in order to make the programs work.

The following links provide additional documentation about shared memory and message queues:

Message Queues: http://beej.us/guide/bgipc/output/html/multipage/mq.html Shared Memory: http://beej.us/guide/bgipc/output/html/multipage/shm.html

Bonus

Implement separate versions of sender and receiver which instead of relying on messagequeues to signal events, rely purely on signals. Hint: use handlers for SIGUSR1 andSIGUSR2.

Hint:howcanyoutellthereceiverthenumberofbytesinthesharedmemory?

This assignmen 1. To solidify your understanding of IPC principles. 2. To develop greater appreciation for the differen IPC mechaaisms, 3. To gain hands-on experience using shared memory To gin hands-om experienceo using message queucs. 5. To gain hands-on experience using signals 6. To learn how to combine sharod menory and message t has the following goals: implement a practical application where the sender process sends information to the receiver process. Overview In this assigoment you will use your knowledge of shared memory and message quues in onder to implement an application which synchronously transfers files between tw proccsscs and the rweiver program as You shall implement two related programs a seuer pgra described below seader: this program shall implement the process that sends files to the receiver process Tt shall perfoem the following sequence of steps: I. The sender shall be inoked as Jsender le.txt where senler is the name of lbe 2. The program shall then attach to the shared memory segment, and connect to th 3. Readu prodefined number of bytes from the specified file, und store these bytes irn 4. Send a message to tbe receiver (using a ussage queve) The mess 5. Wait on the message queue to receive a message from the reeeiver confiming suocess- 6. Go back to step 3. Repeal until the whole file has been read. exautable and file.txt is the name of the file to transfer cmessnge queue both previously set up by the eceiver. the chunk of shared memory liekd called siee mdiculing how many bytes were read Iron the file. ful reception and savingof data to tbe tile by the receiver shall contain a 7. When the end of the file rcachod send a message to the recciver with the size tield ???50 0. Tlig will signalso the roeiver that the sceder will end no more. 8. Cks the file, delach shured memory,and exit - receiver: this program stall imgemet the peocess that receives lsrom the seraler russ shall perform the following eqence of steps: The progrom shall setup a chunk of shaned memory and a meue. 3. The progra shall wait on a mcssape qucuc occive a mcssagc from tlic sendcr size denotingeubr of byls the sem chank svd im the shired memry mcnocy, saves them to the file (lwy called reevtile). sods mssage to tho scader acknolodgingucul recoption and saving of ds, and finally gos back to step 3, . Otherise, isize tield is , thea teprogram ckses the file. detaches the sharod +When user presses Concrol-C in onder to terinate tdherecever, the receer shall de 11ns an hc ?ttrlemcnlc1 hy allwale mermsey and lic tm? ge qsc???.nl thum exd. elting p a signel hiedler loe the SKiINT signal, Sampic file hestrating how to ds this heve been provided (signaidemo cpp) Technleal Details The skeleien axles for seder and receiver can he nd m Titanum The files aea follows - sender.cpp:the skeleun code tor the sender isee the TODo comments in under to fiad out what to fill in out what to fill n It contains the stract of the nessagc relxyed through mesap qacucs The strct . reev.cpp:skclcton codc for the roccer se the TOD0: comas in order to fiod msg.h: the beader file usod by both the scndcr and the roceiver contaias twa fields SENDER DATA TYPE:macro represeating he message sem fom sender to -RECV DONE TYPE: maero repesenting thettesagsett frota #cecover to NOTE: both raessage types have the same structure. The difference is bew the resviver, 'styre is 1. mtype iel. Alsa, the messages of ype RECY DONE TYPEdo not make use of the siac flcld. Makefile: anabls you to huild both sender and receiver by simply typing nake at the command line signaldemacpp: a progrm ilmastrating how to install a signal handler for SIGSTP signal seut to the process when user preses Cootrol-C. Please note: by detault the skeleton programs will give you eerors when you run thea This is because they are accessine unallocated, uaattached regions of shared memmory. It's yeur job to al in the appropriate functionality in the skeleton, de-noted by the TODO comments, in order to make the programs werk. The following links prowidc additional dacaentation about shared mory and mcssage ornes -Mesaige Queaes Bones Implement seprate versors of senderand roeiver which instead ofrlying onmessage gacuss to signal evets, wly purely on signals Hin: se lancters for SKiUSRI and SIGUSR2. Hit:how c you tell the northe numbur of hyls in he sared memory? This assignmen 1. To solidify your understanding of IPC principles. 2. To develop greater appreciation for the differen IPC mechaaisms, 3. To gain hands-on experience using shared memory To gin hands-om experienceo using message queucs. 5. To gain hands-on experience using signals 6. To learn how to combine sharod menory and message t has the following goals: implement a practical application where the sender process sends information to the receiver process. Overview In this assigoment you will use your knowledge of shared memory and message quues in onder to implement an application which synchronously transfers files between tw proccsscs and the rweiver program as You shall implement two related programs a seuer pgra described below seader: this program shall implement the process that sends files to the receiver process Tt shall perfoem the following sequence of steps: I. The sender shall be inoked as Jsender le.txt where senler is the name of lbe 2. The program shall then attach to the shared memory segment, and connect to th 3. Readu prodefined number of bytes from the specified file, und store these bytes irn 4. Send a message to tbe receiver (using a ussage queve) The mess 5. Wait on the message queue to receive a message from the reeeiver confiming suocess- 6. Go back to step 3. Repeal until the whole file has been read. exautable and file.txt is the name of the file to transfer cmessnge queue both previously set up by the eceiver. the chunk of shared memory liekd called siee mdiculing how many bytes were read Iron the file. ful reception and savingof data to tbe tile by the receiver shall contain a 7. When the end of the file rcachod send a message to the recciver with the size tield ???50 0. Tlig will signalso the roeiver that the sceder will end no more. 8. Cks the file, delach shured memory,and exit - receiver: this program stall imgemet the peocess that receives lsrom the seraler russ shall perform the following eqence of steps: The progrom shall setup a chunk of shaned memory and a meue. 3. The progra shall wait on a mcssape qucuc occive a mcssagc from tlic sendcr size denotingeubr of byls the sem chank svd im the shired memry mcnocy, saves them to the file (lwy called reevtile). sods mssage to tho scader acknolodgingucul recoption and saving of ds, and finally gos back to step 3, . Otherise, isize tield is , thea teprogram ckses the file. detaches the sharod +When user presses Concrol-C in onder to terinate tdherecever, the receer shall de 11ns an hc ?ttrlemcnlc1 hy allwale mermsey and lic tm? ge qsc???.nl thum exd. elting p a signel hiedler loe the SKiINT signal, Sampic file hestrating how to ds this heve been provided (signaidemo cpp) Technleal Details The skeleien axles for seder and receiver can he nd m Titanum The files aea follows - sender.cpp:the skeleun code tor the sender isee the TODo comments in under to fiad out what to fill in out what to fill n It contains the stract of the nessagc relxyed through mesap qacucs The strct . reev.cpp:skclcton codc for the roccer se the TOD0: comas in order to fiod msg.h: the beader file usod by both the scndcr and the roceiver contaias twa fields SENDER DATA TYPE:macro represeating he message sem fom sender to -RECV DONE TYPE: maero repesenting thettesagsett frota #cecover to NOTE: both raessage types have the same structure. The difference is bew the resviver, 'styre is 1. mtype iel. Alsa, the messages of ype RECY DONE TYPEdo not make use of the siac flcld. Makefile: anabls you to huild both sender and receiver by simply typing nake at the command line signaldemacpp: a progrm ilmastrating how to install a signal handler for SIGSTP signal seut to the process when user preses Cootrol-C. Please note: by detault the skeleton programs will give you eerors when you run thea This is because they are accessine unallocated, uaattached regions of shared memmory. It's yeur job to al in the appropriate functionality in the skeleton, de-noted by the TODO comments, in order to make the programs werk. The following links prowidc additional dacaentation about shared mory and mcssage ornes -Mesaige Queaes Bones Implement seprate versors of senderand roeiver which instead ofrlying onmessage gacuss to signal evets, wly purely on signals Hin: se lancters for SKiUSRI and SIGUSR2. Hit:how c you tell the northe numbur of hyls in he sared memory

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