[go: up one dir, main page]

0% found this document useful (0 votes)
78 views4 pages

IPC Using Shared Memory

This document describes a program that uses shared memory for interprocess communication (IPC) between a sender and receiver process. The receiver process creates a shared memory segment, stores a user-input message in the segment, and prints the stored message. The sender process attaches to the same shared memory segment, retrieves the stored message, and prints it. This demonstrates basic message passing between two processes using shared memory for IPC.

Uploaded by

zeal4triumph
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views4 pages

IPC Using Shared Memory

This document describes a program that uses shared memory for interprocess communication (IPC) between a sender and receiver process. The receiver process creates a shared memory segment, stores a user-input message in the segment, and prints the stored message. The sender process attaches to the same shared memory segment, retrieves the stored message, and prints it. This demonstrates basic message passing between two processes using shared memory for IPC.

Uploaded by

zeal4triumph
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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