Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

OUTCOME 2 Identify and explain the privacy rights of employees.

Answered: 1 week ago