• 共享内存实现进程间通信


    共享内存实现进程间通信
    #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;
    }





  • 相关阅读:
    codevs 3115 高精度练习之减法 swap
    codevs 3116 高精度练习之加法
    poj 3984 迷宫问题
    codevs m进制转化成10进制
    codevs 1214 线段覆盖
    codevs 3143 二叉树的序遍历
    codevs 3145 汉诺塔
    HDU 5093 Battle ships [二分图匹配]
    HDU 5074 Hatsune Miku [dp] ——2014鞍山现场赛E题
    ZOJ 3793 First Digit (逗比题)
  • 原文地址:https://www.cnblogs.com/ZhangJinkun/p/4531248.html
Copyright © 2020-2023  润新知