#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()
{
int shmid,i;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget
failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat
failed");
return;
}
printf("Enter
text&press$to terminate\n");
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
strcpy(pa,a);
printf("The
given text is placed into shared memory\n");
}
OUTPUT
[user@localhost
~]$ cc mgsh.c
[user @localhost
~]$ ./a.out
Enter
text&press$to terminate
Message stored in
shared memory
shared memory
programs$
The given text is
placed into shared memory
[user @localhost
~]$
No comments:
Post a Comment
Thanks for your valuable comments