You are on page 1of 4

IPC using shared memory-RECEIVER

#include<sys/types.h>
#include<sys/msg.h>
#include<sys/ipc.h>
#include<string.h>
#include<sys/shm.h>
#define SHMKEY 75
#define K 1024
main()
{
int shmid;
char *addr1;

shmid=shmget(SHMKEY,128*K,IPC_CREAT|0600);
addr1=shmat(shmid,0,0);

printf("\n IPC using shared memory");


printf("\n shared memory address is: %x",addr1);
printf("\n Enter the message");
scanf(“%s”,addr1);

printf("\nMessage stored in %x is %s",addr1,addr1);


}
Output:-
IPC using shared memory
Shared memory Address is b7fd1000
Enter the Messgae: Hello
Message stored in b7fd1000 is Hello
IPC using shared memory-SENDER

#include<sys/types.h>
#include<sys/msg.h>
#include<string.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#define SHMKEY 75
#define K 1024
main()
{
int shmid;
char *addr1;

shmid=shmget(SHMKEY,128*K,IPC_CREAT);
addr1=shmat(shmid,0,0);

printf("\n IPC using shared memory");


printf("\n Shared Memory Address is %x",addr1);
printf("\nMessange retrieved from %x is %s",addr1,addr1);
}
Output:-

IPC using shared memory


Shared Memory address is b7fd1000

Message retrieved from b7fd1000 is hello

You might also like