//进程通信,共享存储区
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <fcntl.h>
#include <fcntl.h>

#include<sys/types.h>
#include<sys/shm.h>
#include<sys/ipc.h>

#define SHMKEY 75
int shmid,i;
int *addr;

void client()
{
    int i;
    shmid=shmget(SHMKEY,,);
    addr=shmat(shmid,,);
    ;i>=;i--)
    {
        );
        printf("(client)sent\n");
        *addr=i;
    }
    exit();
}

void server()
{
    shmid=shmget(SHMKEY,,|IPC_CREAT);
    addr=shmat(shmid,,);
    do
    {
        *addr=-;
        );
        printf("(server)received\n");
    }while(*addr);
    shmctl(shmid,IPC_RMID,);
    exit();
}

main()
{
    );
    if(!i)server();
    system("ipcs -m");
    );
    if(!i)client();
    wait();
    wait();
}

sharememory.c的更多相关文章

  1. 利用 MessageRPC 和 ShareMemory 来实现 分布式并行计算

    可以利用 MessageRPC + ShareMemory 来实现 分布式并行计算 . MessageRPC :  https://www.cnblogs.com/KSongKing/p/945541 ...

  2. 我发起了一个 .Net Core 平台上的 分布式缓存 开源项目 ShareMemory 用于 取代 Redis

    Redis 的 安装 是 复杂 的, 使用 是 复杂 的, Redis 的 功能 是 重型 的, Redis 本身的 技术实现 是 复杂 的 . Redis 是用 C 写的, C 语言 编写的代码需要 ...

  3. ShareMemory

    项目地址 :  https://github.com/kelin-xycs/ShareMemory ShareMemory 一个用 C# 实现的 No Sql 数据库 , 也可以说是 分布式 缓存 , ...

  4. 用C#实现的内存映射

    当文件过大时,无法一次性载入内存时,就需要分次,分段的载入文件 主要是用了以下的WinAPI LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD ...

  5. cuda计算的分块

    gpu的架构分为streaming multiprocessors 每个streaming multiprocessors(SM)又能分步骤执行很多threads,单个SM内部能同时执行的thread ...

  6. Windows共享内存示例

    共享内存主要是通过映射机制实现的. Windows 下进程的地址空间在逻辑上是相互隔离的,但在物理上却是重叠的.所谓的重叠是指同一块内存区域可能被多个进程同时使用.当调用 CreateFileMapp ...

  7. 共享内存+互斥量实现linux进程间通信 分类: Linux C/C++ 2015-03-26 17:14 67人阅读 评论(0) 收藏

    一.共享内存简介 共享内存是进程间通信中高效方便的方式之一.共享内存允许两个或更多进程访问同一块内存,就如同 malloc() 函数向不同进程返回了指向同一个物理内存区域的指针,两个进程可以对一块共享 ...

  8. CUDA编程-(2)其实写个矩阵相乘并不是那么难

    程序代码及图解析: #include <iostream> #include "book.h" __global__ void add( int a, int b, i ...

  9. 用PHP实现一个高效安全的ftp服务器(二)

    接前文. 1.实现用户类CUser. 用户的存储采用文本形式,将用户数组进行json编码. 用户文件格式: * array( * 'user1' => array( * 'pass'=>' ...

随机推荐

  1. Linux下rsync的用法

    一.rsync的概述 rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync是Linux系统下的文件同步和数据传输工具,它采用“rsync” ...

  2. 三年.NET即将转Java,我该何去何从

    2014年5月,大三报了某培训班5个月学习.NET 2014年12月-2015年6月,在某软件公司实习,用ASP.NET开发企业级系统 2015年7月-2017年3月,从毕业生到成为该公司的主要开发人 ...

  3. ImportError: No module named yum

    [root@localhost]# yum-complete-transactionTraceback (most recent call last):  File "/usr/sbin/y ...

  4. Scrapy 笔记(一)

    这篇文章主要是对的scrapy命令行使用的一个介绍 创建爬虫项目 scrapy startproject 项目名例子如下: scrapy startproject test1 You can star ...

  5. python爬虫实战(六)--------新浪微博(爬取微博帐号所发内容,不爬取历史内容)

    相关代码已经修改调试成功----2017-4-13 详情代码请移步我的github:https://github.com/pujinxiao/sina_spider 一.说明 1.目标网址:新浪微博 ...

  6. 长安大学第四届ACM-ICPC“迎新杯”程序设计竞赛-重现赛 G - 彩虹岛套娃

    题目描述 俄罗斯套娃是俄罗斯特产的木制玩具,一般由多个一样图案的空心木娃娃一个套一个组成,最多可达十多个,通常为圆柱形,底部平坦可以直立.颜色有红色,蓝色,绿色,紫色等.最普通的图案是一个穿着俄罗斯民 ...

  7. POJ 1597 Function Run Fun

    记忆化搜索. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  8. Sublime 编译运行JavaScript

    Tools > Build System > New Build System... { "cmd": ["node", "$file&q ...

  9. django验证码配置与使用

    1.安装django-simple-captcha pip install django-simple-captcha 2.配置settings.py ##加app列表INSTALLED_APPS = ...

  10. Python中的模块(2)

    1.内置模块2.扩展的 例如:django3.自定义的 文件import demodef read(): print('my read func')demo.read()print(demo.mone ...