易截截图软件、单文件、免安装、纯绿色、仅160KB

linux 进程间共享内存

可以采用sysV的shmget + shmat 实现。
但是我更喜欢shm_open + mmap 更简单。
#---------------------writer.c----------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/mman.h>
struct ofs_stat
{
  int a;
  int b;
  int c;
};
int main(void)
{
        int fd;
    int count = 0;
    struct ofs_stat stat={0};
    struct ofs_stat *s;
    void *region=NULL;
    char *name;
        if((fd=shm_open("ofs_mmm", O_TRUNC|O_CREAT|O_RDWR,0644))==-1) {
      perror("open");
      exit(1);
        }
    ftruncate(fd, sizeof(stat));
    region = mmap(NULL, sizeof(struct stat), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    if(region == (caddr_t)-1) {
      perror("mmap");
      shm_unlink("ofs_mmm");
      return 1;
    }
    s = (struct ofs_stat *)region;
    while(1) {
      s->a=count++;
      printf("%d \n",s->a);
      sleep(1);
    }
        shm_unlink("ofs_mmm");
    return 0;
}
#--------------------reader.c----------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/mman.h>
struct ofs_stat
{
  int a;
  int b;
&


相关文档:

linux 进程通信——信号灯


信号灯与其他进程间通信方式不大相同,它主要提供对进程间共享资源访问控制机制。相当于内存中的标志,进程可以根据它判定是否能够访问某些共享资源,同时,进程也可以修改该标志。除了用于访问控制外,还可用于进程同步。
一、信号灯概述
信号灯与其他进程间通信方式不大相同,它主要提供对进程间共享资源访问控制机制 ......

linux 时间&定时器 介绍

1.时间表示
  在程序当中,我们经常要输出系统当前的时间,比如我们使用date命令的输出结果.这个时候我们可以使用下面两个函数:
  #include
  time_t time(time_t *tloc);
  char *ctime(const time_t *clock);
  time函数返回从1970年1月1日0点以来的秒数.存储在time_t结构之中.不过这个函数的返回值对于我们 ......

Linux的系统管理员,我们离不开这些常用的命令.

  whois
  功能说明:查找并显示用户信息。
  语法:whois [帐号名称]
  补充说明:whois指令会去查找并显示指定帐号的用户相关信息,因为它是到Network Solutions的WHOIS数据库去查找,所以该帐号名称必须在上面注册方能寻获,且名称没有大小写的差别。
  ------------------------------------------------ ......

linux httpd.conf文件配置详解

httpd.conf文件配置详解
Apache的基本设置主要交由httpd.conf来设定管理,我们要修改Apache的相关设定,主要还是通过修改httpd.cong来实现。下面让我们来看看httpd.conf的内容,它主要分成3大部分:
Section 1:Global Environment
Section 2:'Main' server configuration
Section 3:Virtual Hosts
【第一部分】
&mid ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号