bash获取进程ID的方法
ps aux|gawk '$11 == "cmdname" {print $2}'` pidof "cmdname" pgrep "cmdname" [@more@]
erlang for循环
-module(simuagent).-export([forloop/2]).forloop(N,M) -> if N > M -> io:format("simuagent:forloop(N,M), and 0 < N,M <= 1000 ~n"); %%% 循环执行1000次,每次1000个 N<0 orelse N>1000 orelse M<0 orelse M>1000 -> io:format("simuagent:forloop(N,M), and 0 < N,M<= 1000 ~n"); %%% 循环执行1000次,每次1000个 true -> for(N,M,startPushagent) end. for(N,N,startPushagent) -> startPushagent(N); for(N,M,startPushagent) -> start
perl访问memcached
perl访问memcached,效率很高[@more@]#!/usr/bin/perluse strict;use Cache::Memcached;my @servers=("192.168.192.6:11211", "192.168.192.6:11311","192.168.192.6:11411","192.168.192.6:11511");my $pushinfo="192.168.192.8";foreach my $server(@servers){ my $cache = Cache::Memcached->new(servers => [$server]); for(my $i=0;$i<1000000;$i++) { my $key = "10000".("0" x (6- length($i))).$i."0
研究erlang
函数式,并发.[@more@]
linux下查看端口占用的进程
在linux下开发时,你的软件可能要使用某一个端口,或者想查找某一个端口是否被占用。需要怎么做呢??这的确是一个比较烦恼的问题,我也此为这个苦恼过。但是通过查找man手册,还是同事的交流。总结出来两种方法:1)使用lsof命令lsof是一个非常强大的linux工具,她被用来查找哪些程序使用了那些文件。在linux系统下,基本上所有的东西都可以被当作文件来用。socket当然也是一种文件了。所以lsof可以用来查找谁用了某一个端口。具体方法: lsof -i :port_number |grep "(LISTEN)"-i是用来查找和网络相关的文件,":"
cnwap不支持push
因为CMWAP是HTTP Proxy,而Java SocketChannel不支持代理,Socket只支持SOCKS(防火墙)代理,不支持HTTP Proxy。 Java源码也进一步论证了使用Socket HTTP Proxy无法连接HTTP服务器的问题。上层封装的URLConnection或HTTPURLConnection,虽然支持HTTP Proxy,但不支持主动监听模式的推送应用。 如果需要推送服务支持CMWAP网络,则需要自己实现一套Socket HTTP Proxy。 jdk1.6.0_26 /** * Creates an unconnected socket, specifying the type of proxy, if any, * that should be used regardless of any other settings. * * If there is
setsockopt选项
1. 如果在已经处于 ESTABLISHED状态下的socket(一般由端口号和标志符区分)调用closesocket(一般不会立即关闭而经历TIME_WAIT的过程)后想继续重用该socket:BOOL bReuseaddr=TRUE;setsockopt(s,SOL_SOCKET ,SO_REUSEADDR,(const char*)&bReuseaddr,sizeof(BOOL));2. 如果要已经处于连接状态的soket在调用closesocket后强制关闭,不经历TIME_WAIT的过程:BOOL bDontLinger = FALSE; setsockopt(s,SOL_SOCKET,SO_DONTLINGER,(const char*)&bDontLinger,sizeof(BOOL));3.在send(),recv()过程中有时由于网络状况等原因,发收不能预期
防范FIN_WAIT1
防止linux出现大量 FIN_WAIT1,提高性能由 slide 于 星期五, 2009/07/03 - 14:35 发表 FIN_WAIT1 linux当连接数多时,经常出现大量FIN_WAIT1,可以修改 /etc/sysctl.conf修改net.ipv4.tcp_fin_timeout = 10net.ipv4.tcp_keepalive_time = 30net.ipv4.tcp_window_scaling = 0net.ipv4.tcp_sack = 0然后:/sbin/sysctl -p使之生效[@more@]
linux 下各errno的意义
本文转自:http://blog.csdn.net/kofiory/article/details/5790409strerror(errno):获取errno对应的错误/****************************获取错误代码描述**************/#include <string.h>#include <errno.h> /* for strerror */#include <stdio.h>int main(int argc, char ** argv){ int i = 0; for(i = 0; i < 256; i++) printf("errno.%02d is: %s/n", i, strerror(i)); return 0;}/*****************************************************************/[@more@]errno.00 is: Successerrno.01 i
C1000K
C1000K问题已经完全搞定,庆祝下!tcp连接完全okay。安全连接也完全okay。推荐大家参考http://www.kegel.com/c10k.htmlhttp://ecug.googlecode.com/svn-history/r436/trunk/ecug-con/2010/yufeng/ECUG2010-yufeng-C1000K.pdf这些研究却是很不错,不过我的貌似和他们完全不一样的路子,呵呵[@more@]C
1 Million TCP Connection 问题解决
满足100万用户tcp长连接,经过一周奋战,解决。100万tcp长连接,5G内存,平均每个连接5K内存。上线使用每台机器支持10万TCP长连接,上限20万,100万5+2台机器负载均衡,互相热备。硬件平台:4C8G,SUSE10 64Bit功夫不负有心人。庆祝![@more@]
甚么是闪信?
(1) DCS编码格式目前网关可以支持DCS=0(7Bit编码,即Asc码),4(bin方式编码,8Bit编码),8(UCS2编码);15(GB编码)是补充,标准GSM协议中没有GB编码;(2)闪信,就是区别在编码格式GSM规范规定:DCS字段(一个Byte)如果Bit8 Bit7为00,则Bit5-0意义如下:Bit5:是否压缩Bit4:Class是否起作用,Class就是下面Bit0-Bit3Class: Bit3 Bit2 00-〉Default ;01-〉8Bit; 10-〉UCS2(16Bit); 11-〉保留;Bit1 Bit0 00-〉直接显示; 01-〉缺省存储在手机上;10-〉缺省存储在SIM卡上alphabet(字母表);7bit编码闪信 DSC=16 ,0x10;8bit编码闪信
sun平台top10 cpu命令
###显示10个消耗cpu最多的进程prstat -scpu -Z 1 1|head -11 ###显示10个消耗内存最多的进程prstat -srss -Z 1 1|head -11 ###显示10个size的进程prstat -ssize -Z 1 1|head -11 [@more@]un
Aix命令:列出使用内存和Cpu前几位的进程
(1)显示10个消耗cpu最多的进程 # ps aux |head -1 ;ps aux |sort -rn +2 |head -10 (2)显示10个消耗内存最多的进程 #ps vx |head -1 ;ps vx |grep -v PID |sort -rn +6 |head -10 (3)显示10个换页最多的进程 #ps vx |head -1 ;ps vx |grep -v PID |sort -rn +4 |head -10 (4)显示10个消耗存储空间最多的进程 #ps aux |head -1 ;ps aux |sort -rn +3 |head -10[@more@]http://www.aixchina.net/?viewnews-17292.html
几个有用的perl sub
获取当时时间字符串:sub getTime{ my $time = shift || time(); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); $year += 1900; $mon ++; $min = '0'.$min if length($min) < 2; $sec = '0'.$sec if length($sec) < 2; $mon = '0'.$mon if length($mon) < 2; $mday = '0'.$mday if length($mday) < 2; $hour = '0'.$hour if length($hour) < 2; my $weekday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday]; return "$year$
awk
想到要统计个东西,需要用awk。好长时间不用了,都不记得怎么写了。目标是针对每行的第14个域,如果等于56,则统计个数,域之间用,分割。先写一个 cat *.txt|awk -F, 'BEGIN{num=0;} {if($14==56) $num=$num+1;} END{print $num}'运行了下,不对,没结果。把$num=$num+1修改为print $0。把对应的那行打印出来,是对的。估计是统计变量的问题,google了一下,扫了一眼,没有看到直接的描述。再试吧,把$符号去掉。ok了,呵呵。cat *.txt|awk -F, 'BEGIN{num=0;} {if($14==56) num=num+1;} END{print num}'原来awk中外部变量不用带$.真是生疏
STL iterator delete problem
years ago carl report problem in chinaunix.net: bug of stl on hpux.when delete some element in the stl containers,not work.others ok.now i encount the problem again,but not bug.and the solution:for(iterator continue){if(want to delete){delete the pointer;delete the element and move on the cursor;}else{ increment}}and use the r iterator also will be ok.just because when you delete the elemetn.so the iteraotr changed,then error occurs[@more@]
java map
java.util 最常用的集合类之一是Map ,map提供了一个通用的元素存储方法。 Map 集合类用于存储元素对(称作“键”和“值”),其中每个键映射到一个值。常用到的有hashmap和hashtable。[@more@]Map 的接口和方法 覆盖的方法。 我们将这 Object 的这两个方法覆盖,以正确比较 Map 对象的等价性。 equals(Object o)比较指定对象与此 Map 的等价性hashCode()返回此 Map 的哈希码其他方法 clear()从 Map 中删除所有映射remove(Object key)从 Map 中删除键和关联的值put(Object key, Object value)将指定值与指定键相关联clear()从 Map 中删
数组越界的用途
struct tagAAA{int indextype;char sContent[1];};这个sContent正式的说法是可变数组.其实就是合理利用了数组越界.[@more@]
Swing之JTree
向JTree上增加节点的时候,最好的是增加对象,而不是简单的增加一个String对象。这样子需要对象overwrite toString方法,返回该对象的名字,就和你直接插入节点的时候增加String一样。之后可以通过该node的getUserObject 得到你插入的对象,从而可以得到该对象的信息。刷新的时候可以找到对应的节点,setUserObject即可。Suhas coding的时候我没有注意,后来walk through 的时候看到了特意强调了一下,还好,他很快就明白这样子做的好处并且修改了。KLoc接近20K了,还是有不少的问题,IT的时候做的还是不够细,最近在思索怎么能把每一步都