Question: C/Ubuntu: Shared Memory: Customize the following two codes for server and client so that the server creates a 2D 5x5 array and initializes it while

C/Ubuntu: Shared Memory:

Customize the following two codes for server and client so that the server creates a 2D 5x5 array and initializes it while the client code finds the minimum and maximum element in that array through shared memory.

shm_server.c

#include

#include

#include

#include

#define SHMSZ 27

main()

{

char c;

int shmid;

key_t key;

char *shm, *s;

key = 5678;

if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0)

{

perror("shmget");

exit(1);

}

if ((shm = shmat(shmid, NULL, 0)) == (char *) -1)

{

perror("shmat");

exit(1);

}

s = shm;

for (c = 'a'; c <= 'z'; c++)

*s++ = c;

*s = NULL;

while (*shm != '*')

sleep(1);

exit(0);

}

shm_client.c

#include

#include

#include

#include

#define SHMSZ 27

main()

{

int shmid;

key_t key;

char *shm, *s;

key = 5678;

if ((shmid = shmget(key, SHMSZ, 0666)) < 0)

{

perror("shmget");

exit(1);

}

if ((shm = shmat(shmid, NULL, 0)) == (char *) -1)

{

perror("shmat");

exit(1);

}

for (s = shm; *s != NULL; s++)

putchar(*s);

putchar(' ');

*shm = '*';

shmdt(shm);

shmctl(shmid, IPC_RMID, NULL);

exit(0);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!