Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code please. There is similar looking code already on Chegg and everybody seems to be copy and pasting it as a solution although it

image text in transcribed

image text in transcribedimage text in transcribed

C++ code please. There is similar looking code already on Chegg and everybody seems to be copy and pasting it as a solution although it does not work for this problem. Thank you

Here are the codes :

A2q3a.c

#include  #include  #include  #include  #include  #include  #include  #include  int main() { const int SIZE = 4096; const char *name = "Area1"; const char *message= "Hello"; int fd; void *ptr; /* create the shared memory segment */ fd = shm_open(name, O_CREAT | O_RDWR, 0666); /* configure the size of the shared memory segment */ ftruncate(fd,SIZE); /* now map the shared memory segment in the address space of the process */ ptr = (char *) mmap(0,SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); /* Now write to the shared memory region. */ sprintf(ptr,"%s",message); ptr += strlen(message); printf("Finish writing the messages into the shared memory "); return 0; } 

A2q3b.c

#include  #include  #include  #include  #include  #include  #include  #include  int main() { const int SIZE = 4096; const char *name = "Region2"; const char *message= "CSS225 "; int fd; void *ptr; /* create the shared memory segment */ fd = shm_open(name, O_CREAT | O_RDWR, 0666); /* configure the size of the shared memory segment */ ftruncate(fd,SIZE); /* now map the shared memory segment in the address space of the process */ ptr = (char *) mmap(0,SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); /* Now write to the shared memory region. */ sprintf(ptr,"%s",message); ptr += strlen(message); printf("Finish writing the messages into the shared memory "); return 0; } 

A2q3c.c

#include  #include  #include  #include  #include  #include  #include  #include  int main() { const int SIZE = 4096; const char *name = "Space3"; const char *message= "Operating System"; int fd; void *ptr; /* create the shared memory segment */ fd = shm_open(name, O_CREAT | O_RDWR, 0666); /* configure the size of the shared memory segment */ ftruncate(fd,SIZE); /* now map the shared memory segment in the address space of the process */ ptr = (char *) mmap(0,SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); /* Now write to the shared memory region. */ sprintf(ptr,"%s",message); ptr += strlen(message); printf("Finish writing the messages into the shared memory "); return 0; }
Consider these three C programs: A2q3a.c, A2q3b.c, A2q3c.c. These C programs are provided in the Google Classroom's Assignment 2. Each program works as a producer (similar to Example 3 in Lecture Note 2) and stores data in a shared region. Write a C program (named it as "A2q3_Ans.c") who works as a consumer reading the data from these three shared regions and prints them out on the screen in this pattern, for example, 3.2) Compile and run these four C programs in order as follows. You will see an output on the screen. Take a screenshot of your program's output and put here. S225 Operating System 4 3.3) After you have the messages printed on the screen (from 3.2 above), let us run the program "A2q3_Ans" one more time by typing: /A2q3_Ans and press the Enter. You should get this error message: 3) After you have the messages printed on the screen (from 3.2 above), let us run the program "A2q3_Ans" one more time by typing: /A2q3_Ans and press the Enter. You should get this error message: Explain briefly a reason that we get this error message

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

e. What are notable achievements of the group?

Answered: 1 week ago