
linux
文章平均质量分 54
eqxu
无线网络覆盖中的设备管理、用户接入、计费代码的编写、维护
展开
-
查看linux被隐藏进程的内存占用方法,可用于监控进程是否内存泄漏
部分被隐藏的进程ps -aux Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.htmlUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 17017 0.0 0原创 2011-12-22 09:44:45 · 4882 阅读 · 1 评论 -
linux Debugger原理 工作流
推荐google ptrace查看源码http://211.157.110.165/E-book_Video_Audio_Tutorial/20070216/964.pdf原创 2008-02-23 09:20:00 · 1461 阅读 · 0 评论 -
netfilter 防火墙 包过滤 实例
下面这个模块是用来将 #include #include static struct nf_hook_ops user_hook_ops= { { NULL, NULL }, user_hookfn, //用户定义的钩子函数 PF_INET, NF_IP_LOCAL_IN, //挂载点 。对于所有进入本机的数据包(包括使用网络套接字的IPC),都是在此挂载点完成的过滤原创 2007-06-19 16:16:00 · 1666 阅读 · 0 评论 -
地址转换函数 inet_* inet_addr inet_aton ...
注意程序的数据的endian头文件的包含#include //bzero memset#include //struct in_addr#include //AF_INET#include //inet_*int main(int argc, char **argv) { char str[]="172.16.10.196"; char str1[16]; struct in_add原创 2007-06-14 10:05:00 · 3408 阅读 · 0 评论 -
inet_pton inet_ntop 注意点使用
#include //bzero memset#include //struct in_addr#include //AF_INET#include int main(int argc, char **argv) { char str[]="172.16.10.196";// char str1[16]; struct in_addr myin; int ret = 1; unsign原创 2007-06-13 17:29:00 · 10385 阅读 · 1 评论 -
shutdown函数 glibc函数
int shutdown(int sockfd, int how); sockfd 是你想要关闭的套接字文件描述复。how 的值是下面的其中之 一:0 – 不允许接受//可读 关闭1 – 不允许发送//可写 关闭2 – 不允许发送和接受(和 close() 一样)//双向关闭shutdown() 成功时返回 0,失败时返回 -1(同时设置 errno。) 如果在无连接的数据报套原创 2007-06-15 14:38:00 · 1212 阅读 · 0 评论 -
select 函数 使用
告知内核等待某一或某些事件发生 而后唤醒进程 或超时返回 int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *excepset, const struct timeval *timeout); 返回准备好的描述符数量 超时返0错误-1 主要功能:对I/O读 写 异常的监控;原创 2007-06-15 10:57:00 · 1245 阅读 · 1 评论 -
不同套接口比较
原创 2007-06-13 16:06:00 · 785 阅读 · 0 评论 -
linux 指针参数所指向空间大小的计算 malloc realloc alloc 指针指向空间的大小的计算 malloc_chunk结构
原理:glibc中的内存动态分配时通过一个结构来实现的struct malloc_chunk{INTERNAL_SIZE_T prev_size; /* 如果前一个结构未使用则把这个填充为前一结构的size*/INTERNAL_SIZE_T size; /* 本结构的size,最小16(本结构的大小),因为是8字节对齐,最后的三位用来做标记位 PREV_INUSE(最后一位用来标记前一结构原创 2007-06-12 11:00:00 · 5022 阅读 · 0 评论 -
linux 环境下 用gethostbyname函数获取 DNS的服务器列表 名称 IP
#include #include //gethostbyname//#include //struct in_addr()#include void getHostName(){ struct hostent *myhost; char ** pp; struct in_addr addr; myhost = gethostbyname("www.sohu.com"); printf(原创 2007-06-07 13:57:00 · 3874 阅读 · 0 评论 -
网络 服务端 建立服务监听描述符 socket setsockopt(reuse) bind listen
#define LISTENQ 20int open_listenfd(int port){ int listenfd,optval = 1; struct sockaddr_in serveraddr; if ((listenfd = socket(AF_INET,SOCK_STREAM,0)) { return -1; } if(setsockopt(listenfd,SOL_SOC原创 2007-06-08 09:44:00 · 3782 阅读 · 1 评论 -
linux shell 编程 调用过程 fork execve 组合拳
parseline (cmdline,argv); //将用户输入的CMDLINE 进行处理,分开命令行和参数i f (argv[0] == NULL) return;//含有数据if((pid=myFork( ) ) ==0) {//子进程中调用if{execve(argv[0], argv , environ) exit(0);}}if (waitPid( p原创 2007-06-04 14:36:00 · 1456 阅读 · 0 评论 -
网络 客户端 多种方法 建立与服务端的连接 接口:服务器名,IP socket connect
#include #include #include #include #include #include #include //gethostbyname//#include //struct in_addr()#include #include typedef struct sockaddr SA; typedef struct sockaddr_in SIN; in原创 2007-06-07 16:37:00 · 1831 阅读 · 0 评论 -
网络编程 客户端 服务端 函数 流程 图示 来自深入理解计算机系统一书 P704
其中rio前缀代表Robust io 函数库原创 2007-06-07 15:13:00 · 1329 阅读 · 0 评论 -
linux 文件操作函数 通过例子来解释 父子间文件描述符共享 内存映像图
#include #include #include #include #include #include void cyg_error(char * msg){ printf("%s:%s/n",msg,strerror(errno)); exit(0);}//构建自己的安全的fork函数pid_t myFork(){ pid_t mypid; if ((mypid = fo原创 2007-06-07 10:35:00 · 960 阅读 · 0 评论 -
查看程序运行失败后core文件给出的信息
1、如果没有core文件生成可以如下配置: ulimit -c 结果可能是0;用ulimit -c unlimited命令开启2、 查看core文件给出的信息 #include int main() { char *p = NULL; char *q = "123"; memcpy(p,q,4);原创 2007-08-29 14:38:00 · 1904 阅读 · 0 评论 -
data[0] 的妙用
int data[0];printf("sizeof data[0] is %d/n",sizeof(data)); 结果:sizeof data[0] is 0通过上面的例子可以得出一个结论 这么定义一个数组其意义就是定义一个别名 在linux的经典应用:skb 中的data举例://下面的结构体定义了两种TLV#pragma pack(1)struct STUT原创 2007-08-22 16:36:00 · 5767 阅读 · 0 评论 -
部分GNU代码片 5、两个time_t之间的差(天、周、月)
//tEnd到tBegin的时间差 0 代表在同一个时间单位内、例如同一天、周、月static inline int getDaysSub( time_t tBegin, time_t tItem){ return (tItem-tBegin)/86400;}static inline int getWeeksSub( time_t tBegin, tim原创 2008-03-16 22:20:00 · 804 阅读 · 0 评论 -
部分GNU代码片 11、合并文件
//合并文件static inline int Merge(const char* src_filename, const char* dst_filename){ int dst_fd = 0, src_fd = 0; unsigned long long dst_size = 0, src_size = 0; unsigned dst_count = 0, src_count原创 2008-03-19 17:37:00 · 791 阅读 · 0 评论 -
部分GNU代码片 8、程序的配置文件解析部分辨别代码
string argv1 = argc > 1 ? argv[1] : ""; stCFG ostCFG; //param struct if (argc != 2) { cerr exit(1); } if (argv1.find("--help") != string::npos) {原创 2008-03-16 22:26:00 · 691 阅读 · 0 评论 -
如何察看当前服务器上的time_wait sock的多少
netstat -n |awk {print $6} |sort |uniq -c |sort -rn原创 2008-05-29 16:47:00 · 1013 阅读 · 0 评论 -
如何减少TCP TIME_WAIT 套接字数量
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1net.ipv4.ip_local_port_range = 1024 65000net.ipv4.tcp_max_tw_buckets = 30000 net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TC原创 2008-05-28 17:23:00 · 1624 阅读 · 0 评论 -
部分GNU代码片 19、快速的memcpy
#include stdio.h>#include stdlib.h>/**//* for small memory blocks (*/#define small_memcpy(to,from,n)...{register unsigned long int dummy;__asm__ __volatile__( "rep; movsb" :"=&D"(to), "=&S"(from),原创 2008-04-23 15:32:00 · 1330 阅读 · 0 评论 -
部分GNU代码片 18、字符串操作
size_t strlcat( register char* s, register const char* t, register size_t n){ const char* o = t; if (n) { while (--n && *s) s++; if (n) do原创 2008-04-22 21:00:00 · 771 阅读 · 0 评论 -
Understanding MySQL Internals 3:搭建环境
Downloading with free client: Download the client if you have not already done so Download URL is http://www.bitmover.com/bk-client2.0.shar Unpack it and build it:原创 2008-04-15 16:34:00 · 1166 阅读 · 0 评论 -
Understanding MySQL Internals 2:模块图解
原创 2008-04-13 12:25:00 · 2077 阅读 · 0 评论 -
Understanding MySQL Internals 1:学生应该如此这般的学习mysql
Good things happen when you push yourself outside of your comfort zone, doing what is difficult but what you know deep inside is the right thing to do. I wrote an email with a proposal to O’Reilly.原创 2008-04-13 11:16:00 · 1408 阅读 · 0 评论 -
部分GNU代码片 17、GDB调试so的方法
许多服务器都使用了框架,那么如何调试so就成了问题1、假设我的可执行程序是ServerName,共享库为worker.so2、我用gdb调试ServerName,想在B的某个源文件(比如worker.cpp,worker.cpp与ServerName不在同一个目录下)中设置断点,使用下面的命令行break worker.cpp:123若找不到源文件可使用如下命令设定源文件目录:设定gd原创 2008-03-30 21:57:00 · 2361 阅读 · 0 评论 -
部分GNU代码片 13、函数中malloc内存,函数外用
#include #include #include using namespace std;struct sTest{ int a; int b;};int ppfunc(sTest **pt){ *pt =(sTest *) malloc(32); return 0;}int main(){ sTest *pt; ppfunc(&pt);原创 2008-03-27 15:06:00 · 899 阅读 · 0 评论 -
部分GNU代码片 16、GDB调试多线程的方法
#include #include #include #include #include #include void *print_message_function1( void *ptr);void *print_message_function2( void *ptr);int main(){ pthread_t thread1, thread2; ch原创 2008-03-28 09:50:00 · 1059 阅读 · 0 评论 -
部分GNU代码片 15、GDB调试多进程的方法
#include #include #include #include intmain (){ pid_t pid; pid=fork(); if (pid printf("error in fork!"); else if (pid == 0) { i原创 2008-03-28 09:29:00 · 992 阅读 · 0 评论 -
部分GNU代码片 14、获取文件长度的两种方法 fopen open
pf = fopen(file, "r"); if (!pf) { cout return FILE_OPEN_ERROR; } struct stat statBuf; stat(file, &statBuf); //如果是没有数据的"空文件",时间则为昨天 //否则,是文件记录的时间 cout原创 2008-03-27 17:41:00 · 2257 阅读 · 1 评论 -
部分GNU代码片 12、给出年月日求天数
long calc_daynr(uint year,uint month,uint day){ long delsum; int temp; if (year == 0 && month == 0 && day == 0) DBUG_RETURN(0); /* Skip errors */ if (year { if ((year=year原创 2008-03-26 21:26:00 · 689 阅读 · 0 评论 -
部分GNU代码片 6、split
/***************************************************************************** * @brief 函数find_keyword * * 从data中获取参数key的值,data是以,作为分隔符 * @param data 原数据 * @param key 要查找的参数 * @par原创 2008-03-16 22:21:00 · 776 阅读 · 0 评论 -
部分GNU代码片 9、当前时间 精确到us
static inline double time_cost(void){#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec);#else struct原创 2008-03-17 21:31:00 · 761 阅读 · 0 评论 -
部分GNU代码片 7、mysql接口
//头文件#ifndef MYSQL_TOOL_H_#define MYSQL_TOOL_H_#include #include #include #include /** * /file Magic_Mysql.hh * /brief this file supplied common mysql access API. */ /** * Magic_Mysql used原创 2008-03-16 22:24:00 · 819 阅读 · 0 评论 -
部分GNU代码片 10、二叉堆(Binary Heap)
n个关键字序列Kl,K2,…,Kn称为堆,当且仅当该序列满足如下性质(简称为堆性质):(1) a[i]≤a[i*2]且a[i]≤a[2*i+1] 或(2)a[i]≥a[i*2]且a[i]≥a[2*i+1](1≤i≤堆的元素个数 )struct binheap { unsigned magic;#define BINHEAP_MAGIC 0xf581581aU /* from /dev/ran原创 2008-03-17 21:37:00 · 879 阅读 · 0 评论 -
数据提取 “1,123,123,52” 这种信息存储方式的分离
#include #define MAXITEMS 10int main(){ char ca[] = "1,23,"; int ia[MAXITEMS] = {0}; char *pc = ca; int i=0; while(strstr(pc,",")) { ia[i] = atoi(pc);原创 2007-08-22 16:41:00 · 715 阅读 · 0 评论 -
dll / class 运行时装载
DLL装载步骤:(缺页中断时才真正的加载入内存空间)1、调入dll文件分配内存2、确定程序入口点(分配入口指针)对加密的.class文件:1、用类库加载器ClassLoader,把类文件当做数据流读入到一个byte[]中2、对这个 byte[]进行解密处理后(没加密当然就不用做这步了)3、再通过 byte[] 生成一个类4、分配内存5、确定程序入口点原创 2007-08-21 15:28:00 · 774 阅读 · 0 评论 -
宏定义 #号 ##号
/*When a macro parameter is used with a leading ‘#’, the preprocessor replacesit with the literal text of the actual argument, converted to a string constant.#define WARN_IF(EXP) /do { if (EXP) /p原创 2007-07-12 10:43:00 · 1151 阅读 · 0 评论