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;
&
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
[转]linux启动时挂载rootfs的几种方式
一直对linux启动时挂载根文件系统的过程存在着很多疑问,今天在水木精华区找到了有用的资料,摘录如下:
1。linux启动时,经过一系列初始化之后,需要mount 根文件系统,为最后运行init进程等做准备,mount
根文件系统有这么几种方式:
1)文件系统已经存在于硬盘(或者类似的设备 ......
whois
功能说明:查找并显示用户信息。
语法:whois [帐号名称]
补充说明:whois指令会去查找并显示指定帐号的用户相关信息,因为它是到Network Solutions的WHOIS数据库去查找,所以该帐号名称必须在上面注册方能寻获,且名称没有大小写的差别。
------------------------------------------------ ......
众所周知,网络安全是一个非常重要的课题,而服务器是网络安全中最关键的环节。Linux被认为是一个比较安全的Internet服务器,作为一种开放源代码操作系统,一旦Linux系统中发现有安全漏洞,Internet上来自世界各地的志愿者会踊跃修补它。然而,系统管理员往往不能及时地得到信息并进行更正,这就给黑客以可乘之机。相对于这 ......