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

Linux 惊群现象

        在linux中,惊群现象已经消失了的,我们可以看   http://simohayha.javaeye.com/blog/561424 ,但是当我们在开发服务器时候,需要使用epoll,发现一个问题,就是当一个请求过来的时候,发现有的时候被唤起的进程不止一个,看下面的程序:#include <sys/socket.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#define KEY 1234
#define SIZE 1024
#define PORT 9999
#define MAXFDS 5000
#define EVENTSIZE 100
void process();
int fd, cfd,opt=1;
int shmid;
char *shmaddr;
struct shmid_ds buf;
int num = 0 ;
int main(int argc, char *argv[])
{
shmid = shmget(KEY,SIZE,IPC_CREAT|0600); /* 建立共享内存 */
if(shmid == -1){
printf("create share memory failed\n");
}
shmaddr = (char *)shmat(shmid,NULL,0);
if(shmaddr == (void *)-1){
printf("connect to the share memory failed: %s",strerror(errno));
return 0;
}
strcpy(shmaddr,"1\n");

struct sockaddr_in sin, cin;
socklen_t sin_len = sizeof(struct sockaddr_in);
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) <= 0)
{
fprintf(stderr, "socket failed\n");
return -1;
}
memset(&sin, 0, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
sin.sin_port = htons((short)(PORT));
sin.sin_addr.s_addr = INADDR_ANY;
if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) != 0)
{
fprintf(stderr, "bind failed\n");
return -1;
}
if (listen(fd, 32) != 0)
{
fprintf(stderr, "listen failed\n");
return -1;
}
int i ;
for(i = 0; i < 2; i++)
{
int pid = fork();
if(pid == 0)
{


相关文档:

Linux iptable文档

总览
用iptables -ADC 来指定链的规

,-A添加 -D删除 -C 修改
iptables - [RI] chain rule num rule-specification[option]
用iptables - RI 通过规则的顺序指定
iptables -D chain rule num[option]
删除指定规则
iptables -[LFZ] [chain][option]
用iptables -LFZ 链名 [选项]
iptables -[NX] chain
用 -NX ......

Linux压缩与解压缩参数说明

tar命令: tar [-cxtzjvfpPN] 文件与目录 ....
# f+ E' `# d' W( {参数: & e( U# Y4 x; c$ b2 O; j/ p
-c :建立一个压缩文件的参数指令(create 的意思);
. E' {. v5 ^  \' v3 O5 H, C' @- p& ^-x :解开一个压缩文件的参数指令! 3 |& u2 z: k( A# ?% c
-t :查看 tarfile 里面的文件!
9 ......

iostat来对linux硬盘IO性能进行了解

转载本站文章请注明,转载自:扶凯[http://www.php-oa.com]
本文链接: http://www.php-oa.com/2009/02/03/iostat.html
 以前一直不太会用这个参数。现在认真研究了一下iostat,因为刚好有台重要的服务器压力高,所以放上来分析一下.下面这台就是IO有压力过大的服务器
$iostat -x 1
Linux 2.6.33-fukai (fukai-lap ......

LINUX c++线程池框架

版权声明:原文地址及作者不详,如有侵权,请联系;
本文给出了一个通用的线程池框架,该框架将与线程执行相关的任务进行了高层次的抽象,使之与具体的执行任务无关。另外该线程池具有动态伸缩性,它能根据执行任务的轻重自动调整线程池中线程的数量。文章的最后,我们给出一个简单示例程序,通过该示例程序,我们会发现, ......

Linux常用命令

vi编辑命令
进入编辑模式 --> i (insert) 或者 a (append)
进入命令模式 --> Esc
命令模式常用操作:
删除一行 --> dd
复制一行 --> yy
粘贴 --> p ( yy 和 p 是结合使用)
替换 --> :s/oldwords/newwords 替换当前行 :%s/oldwords/newwords 替换所有
注:特殊字符用"\"转义&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号