Answered step by step
Verified Expert Solution
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 =
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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started