|
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/types.h>
- #include <string.h>
- #define BUF_SIZE 100
- int main()
- {
- key_t key = ftok(".", 11);
- int iShmID = shmget(key, BUF_SIZE, IPC_CREAT | 0666);
- if (-1 == iShmID)
- {
- return -1;
- }
- printf("shmget ok\r\n");
-
- void *p = shmat(iShmID,NULL,0);
- if (NULL == p)
- {
- //delete
- return -1;
- }
- int i = 0;
- char *p1 = (char *)p;
- for (i=0;i<10;i++)
- {
- printf("%c ", p1[i]);
- }
- printf("\r\n");
- shmdt(p);
- printf("ok\r\n");
- shmctl(iShmID,IPC_RMID, NULL);
- return 0;
- }
復(fù)制代碼
|
|