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

linux下共享内存(shm)使用示例

#include <sys/ipc.h>
#include <stdio.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#define PERM IPC_CREAT //S_IRUSR|S_IWUSR
#include <errno.h>
int main(int argc,char **argv)
{
int shmid[2048];
char *p_addr,*c_addr;
if(argc!=2)
{
fprintf(stderr,"Usage:%s InputString\n\a",argv[0]);
return 1;
}
int i =0;
for ( i = 0; i<1024; i++ )
{
char *p = new char[1024*1024];
if ( NULL == p )
{
printf( "error new\n" );
return -1;
}
}
for ( i =0; i<1026; i++ )
{
if((shmid[i]=shmget(IPC_PRIVATE,/*1610612736*/ 1024*1024,PERM))==-1)
{
fprintf(stderr,"Create Share Memory Error:%s\n\a",strerror(errno));
return 1;
}
{
p_addr=(char*)shmat(shmid[i],0,0);
p_addr[0] = i/1000 + '0';
p_addr[1] = i%1000/100 + '0';
p_addr[2] = i%100/10 + '0';
p_addr[3] = i%10 + '0';
p_addr[4] = '\0';
printf( "%d, %s\n", i, p_addr );
}
}
}


相关文档:

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

Linux设备模型之input子系统详解

一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......

Linux查看文件夹大小的命令

[root@ns1 opt]#  du -h -s /* | sort
12K     /mnt
13M     /sbin
16K     /lost+found
1.8G    /usr
194M    /root
22G     /opt
24K     /tmp
4.0K&n ......

linux下udp客户端源码示例

#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <s ......

linux下IP v6 tcp服务器端源码示例

/******************************
*
* server.c
*
******************************/
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<errno.h>
#include<string.h>
#include<netinet/in.h>
#include<sys/wait.h> ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号