Question: distruibuted program... okay so sim having trouble with my: Both programs are suppose attach to the same shared memory segment. The consumer reads the message,
distruibuted program... okay so sim having trouble with my:
Both programs are suppose attach to the same shared memory segment.
The consumer reads the message, modifies it eg converts it to uppercase and then writes the modified message back into the shared memory. please attach photo of the teminals showing the output:
my consusmesr files: #include
#include
#include
#include
#include
#include
#include shmcom.h
void touppercasechar str
while str
str toupperunsigned charstr;
str;
int main
void sharedmemory void ;
struct sharedusest sharedstuff;
int shmid;
shmid shmgetkeyt sizeofstruct sharedusest IPCCREAT;
if shmid
fprintfstderr "shmget failed
;
exitEXITFAILURE;
sharedmemory shmatshmidvoid ;
if sharedmemory void
fprintfstderr "shmat failed
;
exitEXITFAILURE;
printfMemory attached at p
sharedmemory;
sharedstuff struct sharedusest sharedmemory;
int running ;
while running
if sharedstuffwrittenbyyou
printfReceived message: s sharedstuffsometext;
Modify the message
touppercasesharedstuffsometext;
printfModified message to uppercase: s sharedstuffsometext;
sharedstuffwrittenbyyou ;
if strncmpsharedstuffsometext, "END",
running ;
else
sleep;
if shmdtsharedmemory
fprintfstderrshmdt failed
;
exitEXITFAILURE;
Delete the shared memory segment
exitEXITSUCCESS;
and here is my producer file:
#include
#include
#include
#include
#include
#include shmcom.h
int main
int running ;
void sharedmemory void ;
struct sharedusest sharedstuff;
char bufferBUFSIZ;
int shmid;
shmid shmgetkeyt sizeofstruct sharedusest IPCCREAT;
if shmid
fprintfstderr "shmget failed
;
exitEXITFAILURE;
sharedmemory shmatshmidvoid ;
if sharedmemory void
fprintfstderr "shmat failed
;
exitEXITFAILURE;
printfMemory attached at p
intsharedmemory;
sharedstuff struct sharedusest sharedmemory;
whilerunning
whilesharedstuffwrittenbyyou
sleep;
printfwaiting for client...
;
printfEnter some text: ;
fgetsbuffer BUFSIZ, stdin;
strncpysharedstuffsometext, buffer, TEXTSZ;
sharedstuffwrittenbyyou ;
if strncmpbuffer "end",
running ;
if shmdtsharedmemory
fprintfstderrshmdt failed
;
exitEXITFAILURE;
exitEXITSUCCESS;
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
