自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

码农

耕田种地

  • 博客(248)
  • 资源 (4)
  • 收藏
  • 关注

原创 vmstat

解读 Linux 性能指标vm modevmstat [options] [delay [ count]]-S: 内存显示单位delay The first line of data returned by vmstat reports averages since the system was booted. The subsequent lines are averages within

2016-10-04 20:12:29 778

原创 top

top, free 与虚存管理常用选项(COMMAND-LINE Options)-a : Sort by memory usage. 以 %MEM 排序,默认以 %CPU 排序 -M : -M : Detect memory units. 以 human-readable 单位显示内存占用 -p : Monitor PIDs as: -pN1 -pN2 … or -pN1, N2 [,…

2016-10-04 15:32:46 759

原创 netstat

子命令netstat: 不加子命令,可用 ss 代替; Display a list of open sockets.netstat -r: –route, 可用 ip route 代替; Display the kernel routing tables.netstat -i: –interface, 可用 ip -s link 代替; Display a table of all n

2016-10-03 17:05:15 8179

原创 ps

常用选项-e: Select all processes. Identical to -A. -f: does full-format listing, can be combined with many other UNIX-style options to add additional columns. When used with -L, the NLWP (number of thread

2016-10-03 16:03:19 793

原创 hping - 使用 TCP/UDP ping 解决防火墙拦截 ICMP ping

使用场景暴露在外网环境的服务通常会只对白名单内的来源机器开放服务使用的端口,比如 B 机器只对 A 机器开放 TCP 8999 端口,这样会导致 A ping B 收不到回包,无法查看 TTL 与丢包率。 hping 能指定 IP/ICMP/TCP/UDP 进行 ping, 对于上述场景,使用 hping 的 TCP 模式即可解决。hping 支持的模式# hping --helpMode

2016-09-14 15:50:45 15906

原创 tcpdump 分析 TCP 通信过程

step1: connect(client)14:26:17.213856 IP 172.25.40.208.49040 > 172.25.40.208.9999: S 2796874307:2796874307(0) win 32767 <mss 16396,sackOK,timestamp 166610063 166607508,nop,wscale 2>14:26:17.213876 IP

2016-06-20 17:09:28 572

原创 tcpdump

命令格式tcpdump [option] [expression]重要选项-i : 指定读取 packets 的网卡,如果不指定,以读取序号最小的网卡,如系统存在 eth0 和 eth1, 则读取 eth0 的。 Note: 如果是本机与本机之间通信,请使用 -i lo, 即使绑定的地址不是 loopback 地址。-w , -r : 将 packets 写入文件和从文件读入 packets, 这

2016-06-20 17:04:02 470

原创 iptables

iptables is a user-space application program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different Netfilter modules) and the chains and rule

2016-06-12 19:40:19 603

原创 使用 dmesg 和 addr2line 分析程序 core 原因

今天遇到这样一种情况:发现进程 tagent 在发送响应时退出了,退出原因未知,因为没有 core 文件,无从分析。core 文件生成目录和 ulimit 都没有任何问题,就是不生成 core 文件:$ cat /proc/sys/kernel/core_patterncore.%p_%e$ ulimit -cunlimited写了个小程序也能生成 core, 没有 core 文件,只能另觅他径

2016-04-13 17:49:55 3978 1

原创 64位和32位平台下C/C++结构内存对齐

1. 在 64 位 Linux 下,结构体字段默认按 8 字节对齐;32 位 Linux 下,默认 4 字节对齐。2. 显示指定对齐方式时,会受到机器字长的约束,即 64 位 Linux 下可以按 8 字节及以下的任意字节对齐,32 位只能按 4 字节及以下任意字节对齐。#include #pragma pack(4)struct Test{ char c; long long

2016-03-07 11:26:55 6035

原创 popen+pclose 执行 shell 命令

在《system() 执行 shell 命令》中,我们介绍了 system 执行 shell 命令的方法,system 返回值比较混乱,难以理解,而且 popen 在处理子进程标准输出上会很方便。注意:管道只能处理标准输出,不能处理标准错误输出。popen 和 pclose 的实现与 system 类似,多了一步创建管道的操作。popen 成功返回 FILE 句柄,失败返回 N

2016-02-18 21:53:46 10477

原创 显式调用析构函数与栈中 new 对象

#include #include class Test{public: Test(int ii) : i(ii) {} ~Test() { std::cout << i << std::endl; } public: int i;};int main(int argc, char* argv[]){ // #test will be d

2016-01-12 15:44:33 847

原创 curl 命令

get requestcurl "param1=value1¶m2=value2" http://www.xxx.compost requestcurl -d "param1=value1¶m2=value2" http://www.xxx.com-d/--data 输出至文件时不输出统计信息当将结果输出至文件或重定向至文件时,会出现如下统计信息: % T

2015-12-30 18:39:50 607

原创 system() 执行 shell 命令

实现原理strace 跟踪结果:clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD, parent_tidptr=0x7fff936fc388) = 15661wait4(15661, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 15661实际的过程:1. 父进程 -

2015-12-16 15:11:24 6070

原创 C++ string 陷阱—— append() 与相加

#include #include #include // xxx.so --> xxx --> xxx_get_instint main(){ std::string so_name = "xxx.so"; const char* dot_pos = strstr(so_name.c_str(), "."); if (NULL == dot_pos)

2015-12-11 13:05:23 5665 2

原创 memmove and memcpy

区别:memmove 重叠时能保证 dst 数据正常,但 memcpy 就不会保证了。#include #include int main(){ // case 1: not overlap char str[6] = "12345"; memmove(str + 2, str, 2); printf("memmove: %s\n", s

2015-11-05 11:30:49 728

原创 C 常用基本类型的原型——time_t, size_t 等

time_t/usr/include/time.htypedef __time_t time_t;/usr/include/bits/time.hstruct timeval { __time_t tv_sec; /* Seconds. */ __suseconds_t tv_usec; /* Microseconds. */ }

2015-10-29 21:55:51 8333

原创 errno 的坑

由于 strtoll, strtoull 返回值不能标识处理是否成功,所以需要借助 errno, 看下面这段代码:#include #include #include int main(int argc, char* argv[]){ if (argc != 2) { printf("Usage: %s \n", argv[0]); r

2015-08-28 12:30:46 1282

原创 URI(URL) 允许的字符

URI所允许的字符分作保留与未保留。保留字符是那些具有特殊含义的字符. 例如, 斜线字符用于URL (或者更一般的, URI)不同部分的分界符. 未保留字符没有这些特殊含义. 百分号编码把保留字符表示为特殊字符序列。上述情形随URI与URI的不同版本规格会有轻微的变化。RFC 3986 section 2.2 保留字符 (2005年1月)! * '( ) ; : @&

2015-08-25 20:50:35 10287

原创 元素为自定义复合结构时 map,set 如何处理重复 key 及排序?

map, set 为 类模板,默认使用的 comparator 为类模板 less, 因此我们需要重载关系运算符 ".下面的例子是一个排行榜,排序规则如下:1. 按分数由高到低排;2. 分数一样的情况下,按时间由新到旧排;3. 时间也一样的情况下,按用户 ID 由小到大排。#include #include namespace test{ // sorted

2015-07-26 13:50:33 2153

原创 kill 命令

kill 默认信号:-15(SIGTERM), 有些进程 -15 杀不死,就用 -9(SIGKILL).kill -9

2015-07-18 18:06:05 708 1

原创 常见 core dump 原因分析signal 11 - SIGSEGV

signal 6 - SIGABRTfree 多次char *p = malloc(100);free(p);free(p);fclose 多次// fclose 内部调用 freeFILE *fp = fopen("test.txt", "wb+");printf("%p\n", fp);fclose(fp);printf("%p\n", fp);fc

2015-07-09 15:09:50 90046 2

原创 进程收不到网络数据,但 tcpdump 能抓到包

情景:服务端进程绑定了 udp://0.0.0.0:10004 端口,客户单一直在往服务端发送数据,但是 strace 发现,服务端进程一直都在轮询调用 epoll_wait, 也就是服务端程序一直都没有收到过时间通知。但是通过 tcpdump 抓 udp 10004 端口的数据却能抓到。查看了一下 iptables 的配置:Chain ETH1_UDP (1 references)ta

2015-05-22 18:39:22 9281 2

原创 Windows 去除关机选项

去除关机选项gpedit.mscUser Configuration(用户配置)Administrative Templates(管理模板)Start Menu and Taskbar(“开始”菜单和任务栏)Remove and prevent access to the Shut Down, Restart, Sleep, and Hibernate commandsNot Con

2015-05-15 19:33:04 1232

原创 MySQL 注释及特殊语法

三种注释mysql> SELECT 1+1; # This comment continues to the end of linemysql> SELECT 1+1; -- This comment continues to the end of linemysql> SELECT 1 /* this is an in-line comment */ + 1;mysql

2015-05-14 19:12:47 914

原创 Linux 文件锁与 inode

1. 进程 A 排他锁住某文件之后,进程 B 可以修改该文件,但不能锁住该文件。2. 进程 A 排他锁住某文件之后,进程 B 修改该文件之后,因为文件 inode 没有改变,所以依然不能锁住该文件。3. 进程 A 排他锁住某文件之后,进程 B 可以删除该文件,并创建同名文件,此时进程 B 可以锁住该文件。由于 vi, sed 等程序修改文件会改变文件 inode, 所以会导致被 A 进

2015-04-24 20:51:42 1780

原创 vi, sed 等程序竟然后改变文件 inode!!!

创建一个文件 lock.txt, 内容只有 "123" 三个字符:> ls -i lock.txt2172299 lock.txt> vi lock.txt"lock.txt" 1L, 5C 已写入

2015-04-24 20:35:18 1712 3

原创 samba 配置

查看 samba 用户pdbedit -L启动/停止/重启/查看状态service smb status/...添加用户及用户目录smbpasswd -a xxx # 必须是已有的系统用户 # 目录默认为系统家目录Linux 上测试[root@TENCENT64 /usr/local/samba/bi

2015-04-23 14:38:29 753

原创 用 Telnet 检查是否能连接远程 TCP 端口

445 为 samba 服务器绑定的端口:telnet 10.12.16.178 445按 【Ctrl+]】进入 Telnet 命令行:欢迎使用 Microsoft Telnet ClientEscape 字符为 'CTRL+]'Microsoft Telnet>说明连接正常!

2015-04-23 14:35:03 5735

原创 mutex 测试程序

这段程序使用了 C++ 11 中的线程库:// mutex::lock/unlock#include // std::cout#include // std::thread#include // std::mutexstd::mutex mtx; // mutex for critical sectionvo

2015-04-15 11:26:33 1029

原创 Nginx+PHP+MySQL+phpMyAdmin 环境搭建与使用(12.04.4 LTS)

Nginx安装 Nginx~$ sudo apt-get install nginxThe following extra packages will be installed: libgd2-noxpm libjpeg-turbo8 libjpeg8 nginx-common nginx-fullSuggested packages: libgd-toolsThe foll

2015-04-09 22:47:27 9642 1

原创 C++ memset 类对象 crash(core) 的问题

#include class Base1{private: char aChar; short aShort; int aInt; float aFloat;};class Derived1: public Base1{private: char charArray[3]; short shortArray[3]; int

2015-04-07 17:07:39 2039 1

原创 gtest(Google Test)使用

gtest 代码目录结构说明:以 gtest-1.7.0 为例cmake, codegear, make, msvc, xcode构建测试项目的构建文件,如 make 就是 Makefile.To write a test program using Google Test, you need to compile Google Test into a library and li

2015-04-02 20:06:21 3150

原创 多线程、多进程写同一日志情况下的日志库中 I/O 的选型

文件描述符与 inode 相关背景知识出自《The Linux Programming Interface》多线程有上面的背景知识可知,多线程情况下写同一文件用的是同一个【文件偏移量】,因此只要单条写日志操作是原子操作,就不会出现日志混乱的情况。系统 I/O系统 I/O write() 不带应用层缓冲(进程级别缓冲),因此只要保证单条日志操作之调用一次 writ

2015-01-29 12:13:16 3806

原创 单个进程监听多个端口及多个进程监听同一个端口

单个进程监听多个端口单个进程创建多个 socket 绑定不同的端口,TCP, UDP 都行多个进程监听同一个端口(multiple processes listen on same port)通过 fork 创建子进程的方式可以实现,其他情况下不行。当连接到来时,子进程、父进程都可以 accept, 但如果都去处理则会出现问题,造成数据不完整。NGINX 的 m

2015-01-28 12:46:29 17120

原创 Ctrl+Z 暂停程序及重启程序

Ctrl+Z - 停止进程并放入后台jobs - 显示当前暂停的进程bg N 使第N个任务在后台运行fg N 使第N个任务在前台运行bg, fg 不带 N 时表示对最后一个进程操作

2015-01-27 10:40:09 9165 1

原创 gdb 一步一步调试程序

例子:#include #include #include int main (int argc, char *argv[]){ time_t time_stamp; struct tm info; info.tm_year = atoi(argv[1]) - 1900; info.tm_mon = 1 - 1; info.tm_mday =

2015-01-23 11:41:51 4773

原创 CIL 与 PE 格式

PE 格式.exe, .dll 都属于 PE 格式。CIL中间语言不是 C# 的特权,C++/C 等编译型语言都可以生成中间语言。CIL 与 PE 格式.dll, .exe 中包含的并不全是机器码,它既可以包含机器码,也可包含中间语言。 下面这句话出自 Mono:The CLI is able to host C++ compiled code on all

2015-01-16 21:29:03 950

原创 gcc 编译阶段

【编译阶段】预处理 --> 编译成汇编代码 --> 编译成机器码 --> 链接gcc -E: 预处理完之后停止gcc -S: 生成汇编代码之后停止gcc -c: 生成 .o 机器码之后停止cpp: The C Preprocessor. IN: .c, OUT: .i or othersas: The assembler. IN: .S, OUT: .o

2015-01-15 11:35:09 572

原创 C++ 字符串大小写转换

使用 algorithm 中的 transform:#include #include #include int main(){ std::string str = "FrancisHe"; std::transform(str.begin(), str.end(), str.begin(), ::toupper); std::cout << str << s

2015-01-07 15:48:12 1629

The.C.Programming.Language.2nd.Edition.文字版

The C Programming Language, 第二版,英文文字版,经典书籍

2014-05-03

Advanced Programming in the UNIX Environment 2nd Edition 英文文字带书签版

UNIX 环境高级编程,第二版,英文版,书签非常详细

2014-05-03

MySQL性能调优与架构设计--全册

MySQL性能调优与架构设计,文字版,带详细书签

2012-04-28

C99标准-2007年版

ISO2007年发布的C99标准,英文原版,带详细标签

2012-04-28

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除