#include "stdio.h"
#include "string.h"
#include "unistd.h"
#include "sys/shm.h"
int main()
{
int id = shmget(0x8888, 100, IPC_CREAT|0644);
if (id==-1)
{
perror("Error");
return -1;
}
char *p = shmat(id, NULL, 0);
if (p == ((char*)-1))
{
perror("Error");
return -1;
}
strcpy(p, "Hello Shared Memory!");
shmdt(p);
return 0;
}
#include "stdio.h"
#include "string.h"
#include "unistd.h"
#include "sys/shm.h"
int main()
{
int id = shmget(0x8888, 0, 0);
if (id==-1)
{
perror("get Error");
return -1;
}
char *p = shmat(id, NULL, SHM_RDONLY);
if ( p == ((char*)-1))
{
perror("At Error");
return -1;
}
puts(p);
shmdt(p);
shmctl(id, IPC_RMID, 0);
return 0;
}