#include<iostream>
#include<unistd.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
using namespace std;
int main()
{
//创建共享内存 长度是1024 权限为666
int shmid = shmget(IPC_PRIVATE,1024,0666);
if(shmid<0)
{
cout<<"error:"<<shmid<<endl;
}
else
{
cout<<"sucess:"<<shmid<<endl;
}
char* shnmbuf = (char*)shmat(shmid,0,0);
int i=30;
while(i)
{
sleep(1);
cout<<i--<<endl;
}
shmdt(shnmbuf);
return 0;
}
时间: 2024-10-24 05:32:31