Question: Here are the codes: A2q3a.c #include #include #include #include #include #include #include #include int main() { const int SIZE = 4096; const char *name =

#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; }
#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; }
#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; }
3. 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, From A2q3a: From A2q3b: From A2q3c: You will see an output on the sereen. Take a sereenshot of your program's output and put here. 225 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 crror message: Explain briefly a reason that we get this error message
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
