Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
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; }
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

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

Students also viewed these Databases questions