标题:
一段进程
[打印本页]
作者:
fucuhost
时间:
2018-11-2 07:27
标题:
一段进程
#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;
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1