Question: I use an oracle vm box, but I am tasked with: Problem: modifying the program to print values in shared memory both from child and
I use an oracle vm box, but I am tasked with:
Problem:
modifying the program to print values in shared memory both from child and parent alternatively (Sample output given below)
Output:

Program:
#include
int main() { int shmid,status; int *a, *b; int i;
shmid = shmget(IPC_PRIVATE, 2*sizeof(int), 0777|IPC_CREAT);
if (fork() == 0) {
b = (int *) shmat(shmid, 0, 0); for( i=0; i
} else { a = (int *) shmat(shmid, 0, 0);
a[0] = 0; a[1] = 1;
for( i=0; i
shmdt(a);
shmctl(shmid, IPC_RMID, 0); }
return 0; }
Output Sample for question 2 rr@rr-VirtualBox: /Demo\$ ./shmDemo2 Parent writes: 1,2 Parent writes: 3,5 Child reads: 1,2 Child reads: 3,5 Parent writes: 8,13 Child reads: 8,13 Parent writes: 21,34 child reads: 21,34 Parent writes: 55,89 Child reads: 55,89 Parent writes: 144,233 Child reads: 144,233 Parent writes: 377,610 Child reads: 377,610 Parent writes: 987,1597 Child reads: 987,1597 Parent writes: 2584,4181 Child reads: 2584,4181 Parent writes: 6765,10946 Child reads: 6765,10946
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
