无名管道进程间通信

#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;
}





posted @ 2015-05-26 17:50  外禅内定,程序人生  阅读(141)  评论(0编辑  收藏  举报