/
#include<stdio.h>
#include<sys/shm.h>
#include<sys/ipc.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int shmid = shmget((key_t)1234, 100, IPC_CREAT);
if (-1 == shmid)
{
perror("shmget");
exit(1);
}
char *ptr = (char *)shmat(shmid, NULL, 0);
if ((void *)-1 == ptr)
{
perror("shmat");
exit(2);
}
char buffer[100] = {0};
memcpy(buffer, ptr, 100);
printf("%s\n", buffer);
if (-1 == shmdt(ptr))
{
perror("shmdt");
exit(3);
}
return 0;
}
#include<stdio.h>
#include<sys/shm.h>
#include<sys/ipc.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int shmid = shmget((key_t)1234, 100, IPC_CREAT);
if (-1 == shmid)
{
perror("shmget");
exit(1);
}
char *ptr = (char *)shmat(shmid, NULL, 0);
if ((void *)-1 == ptr)
{
perror("shmat");
exit(2);
}
char buffer[100] = {0};
memcpy(buffer, ptr, 100);
printf("%s\n", buffer);
if (-1 == shmdt(ptr))
{
perror("shmdt");
exit(3);
}
return 0;
}