linux两个程序通过共享内存通信的一个简单例子
写共享内存程序:
/*
* File: server.cpp
* Author: centos
*说明:从键盘读入数据,存放在共享内存中。
* Created on 2010年3月1日, 下午3:44
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define BUF_SIZE 1024
#define MYKEY 114
int main(int argc, char** argv)
{
int shmid;
char *shmptr;
struct shmid_ds shmbuf;
system("ipcrm -M114"); //调试程序时用
shmid = shmget(MYKEY, BUF_SIZE, (IPC_CREAT |0777) );
if ( -1 == shmid )
{
printf("server shmget error!\n");
fprintf(stderr, "Error: %d - %s\n", errno, strerror(errno));
exit(1);
}
shmptr = (char *) (shmat(shmid, 0, 0)) ;
if ( -1 == (int) shmptr )
{
printf("server shmat error!\n");
fprintf(stderr, "Error: %d - %s\n", errno, strerror(errno));
if(shmctl(shmid,IPC_RMID,&shmbuf) < 0)
{
perror("shmctl error");
fprintf(stderr, "Error: %d - %s\n", errno, strerror(errno));
}
exit(1);
}
strcpy(shmptr,"this is a test. \n");
while(1)
{
printf("Please input:");
scanf("%s",shmptr) ;
while ('\n' != getchar() );
// fflush(stdin);
// printf("your input: %s\n", shmptr);
if (! strcmp(shmptr,"quit")) break;
}
shmdt(shmptr);
if(shmctl(shmid,IPC_RMID,&shmbuf) < 0) perror("shmctl error");
return (EXIT_SUCCESS);
}
读共享内存的程序:
/*
* File: main.cpp
* Author: centos
*
说明:从共享内存中读取数据,显示到屏幕上。
* Created on 2010年3月2日, 上午10:47
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define BUF_SIZE 1024
#define M
相关文档:
在类unix
操作系统
中,驱动
加载
方式一般分为:动态加载和静态加载,下面分别对其详细论述。
一、动态加载
动态加载是将驱动模块加载到内核
中,而不能放入/lib/modules/下。
在2.4内核中,加载驱动命令
为:insmod ,删除模块为:rmmod;
在2 ......
DBA:Linux
在 Linux x86 上安装 Oracle RAC 10g
作者:John Smiley
了解在 Red Hat Enterprise Linux 或 Novell SUSE Enterprise Linux 上从头安装 Oracle RAC 10g 的基础知识(仅用于评估)
目录
概述
背景
第 1 部分: 安装 Linux
第 2 部分: 为 Oracle 配置 Linux
第 3 部分: 准备共享磁盘
第 4 部分: ......
linux下几种服务器的配置使用之一:nfs tftp
安装nfs需要在服务器端关闭iptables防火墙,关闭方法如下
查看防火墙状态:
/etc/init.d/iptables status
暂时关闭防火墙:
/etc/init.d/iptables stop
禁止防火墙在系统启动时启动
/sbin/chkconfig --level 2345 iptables off
重启iptables:
/etc/init.d/iptabl ......
1.编译安装libevent
2.编译安装Memcached
在我写这篇文章的时候,libevent已经有1.4.8稳定版
,Memcached Server已经有1.3.0版本
。本文就以这两个版本为例,我的gcc是gcc version 3.3.4 (Debian 1:3.3.4-7)。
首先安装libevent
wget http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz
tar zxvf libeven ......