1. #include <stdio.h>
  2. #include <sys/shm.h>
  3. #include <sys/stat.h>
  4. int main ()
  5. {
  6. int segment_id;
  7. char* shared_memory;
  8. struct shmid_ds shmbuffer;
  9. int segment_size;
  10. const int shared_segment_size = 0x6400;
  11. /* Allocate a shared memory segment. */
  12. segment_id = shmget (IPC_PRIVATE, shared_segment_size,
  13. IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  14. /* Attach the shared memory segment. */
  15. shared_memory = (char*) shmat (segment_id, , );
  16. printf (“shared memory attached at address %p\n”, shared_memory);
  17. /* Determine the segment’s size. */
  18. shmctl (segment_id, IPC_STAT, &shmbuffer);
  19. segment_size = shmbuffer.shm_segsz;
  20. printf (“segment size: %d\n”, segment_size);
  21. /* Write a string to the shared memory segment. */
  22. sprintf (shared_memory, Hello, world.”);
  23. /* Detach the shared memory segment. */
  24. shmdt (shared_memory);
  25. /* Reattach the shared memory segment, at a different address. */
  26. shared_memory = (char*) shmat (segment_id, (void*) 0x5000000, );
  27. printf (“shared memory reattached at address %p\n”, shared_memory);
  28. /* Print out the string from shared memory. */
  29. printf (“%s\n”, shared_memory);
  30. /* Detach the shared memory segment. */
  31. shmdt (shared_memory);
  32. /* Deallocate the shared memory segment.
  33. shmctl (segment_id, IPC_RMID, 0);
  34. */
  35. return ;
  36. }

IPC:shared memory的更多相关文章

  1. Oracle:shared memory realm does not exist

    1. 先描述一个连接Oracle 10g的错误:“shared memory realm does not exist” 如图所示Sqlplus连接时出现这个错误: 2. Oracle 服务器主要组件 ...

  2. zabbix登陆问题:cannot allocate shared memory for collector

    问题说明:在一台zabbix被监控服务器上(64位centos6.8系统,64G内容)启动zabbix_agent,发现进程无法启动,10050端口没有起来! 启动zabbix_agent进程没有报错 ...

  3. Linux IPC - Shared memory

    http://blog.163.com/muren20062094@yeah/blog/static/161844416201161974646434/ 1. Create shared memory ...

  4. 错误:Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file

    Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file: /tmp/hsperfdat ...

  5. oracle连接数据库报错:ORA-01034: ORACLE not available(Oracle 不存在),ORA-27101: shared memory realm does not exist

    花一天半的时间解决客户端连接服务端的oracle数据库,无法连接问题.ORA-01034: ORACLE not available(Oracle 不存在),ORA-27101: shared mem ...

  6. 进程间通信IPC:消息队列,信号量,共享内存

    2015.3.4星期三 阴天 进程间通信:IPC 文件对象:记录文件描述符,文件开关等 IPC标示符:系统全局的流水号两个进程要通信,打开的是唯一的对象进行通讯,通过key操作 XSI IPC:消息队 ...

  7. ORA-27101:shared memory realm does not exist的问题

    ORA-27101:shared memory realm does not exist的问题 登陆SQLPlus时出现: ORA-01034:ORACLE not avaiable ORA-2710 ...

  8. Android系统匿名共享内存Ashmem(Anonymous Shared Memory)在进程间共享的原理分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6666491 在前面一篇文章Android系统匿 ...

  9. Android系统匿名共享内存Ashmem(Anonymous Shared Memory)驱动程序源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6664554 在上一文章Android系统匿名共 ...

随机推荐

  1. 那些年一起踩过的坑 — Date类型序列化的问题

      坑在哪里?        序列化 和 反序列化 的时候对Date字段的格式设置不一致        例如:将Java bean序列化成Json string的时候 格式为 yyyy-MM-dd 解 ...

  2. 未能加载文件或程序集“WcfService”或它的某一个依赖项。试图加载格式不正确的程序。

    “/”应用程序中的服务器错误. 未能加载文件或程序集“WcfService”或它的某一个依赖项.试图加载格式不正确的程序. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息, ...

  3. poj 2104 K-th Number(主席树)

    Description You are working for Macrohard company in data structures department. After failing your ...

  4. 使用Dom4j生成xml文件

    场景:使用dom4j生成以下xml文件 <?xml version="1.0" encoding="UTF-8"?> <result> ...

  5. leetcode@ [30/76] Substring with Concatenation of All Words & Minimum Window Substring (Hashtable, Two Pointers)

    https://leetcode.com/problems/substring-with-concatenation-of-all-words/ You are given a string, s, ...

  6. CoreSeek中文检索引擎

    目的:安装coreseek中文检索引擎,配置MySQL数据库访问接口,使用PHP程序实现中文检索. CoreSeek官方网站: http://www.coreseek.cn/ http://www.c ...

  7. BroadcastReceiver学习笔记

    1.在代码中注册与在AndroiManifest.xml注册的区别 (a)在代码中注册可以控制注册与注销的时间.比如在onCreate-onDestory, onStart-onStop, onRes ...

  8. A Tour of Go Switch evaluation order

    Switch cases evaluate cases from top to bottom, stopping when a case succeeds. (For example, switch ...

  9. [Objective-c 基础 - 2.2] OC弱语法、类方法

    A.OC弱语法 1.在运行的时候才会检查方法的声明和实现 2.没有声明只有实现的方法也能正常运行,只要在调用之前定义即可 3.类的声明必须存在,否则会出现运行时错误   B.类方法 1.是类名调用的方 ...

  10. 转载 HTTP常见状态码分析 200 301 302 404 500

    转载原地址:  http://www.cnblogs.com/starof/p/5035119.html HTTP状态码(HTTP Status Code) 一些常见的状态码为: 一.1开头1xx(临 ...