ITeye博客

C 开发札记

fishermen · 2013-08-15 14:12 · C/C++ · 编程语言 · Markdown

记录C开发中一些小知识,备忘~~

    1 man 手册

1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]

     man 按章节顺序号查找,所以如果想查函数,直接用man 2 XX or man 3 XX。

 

2 linux 支持的标准signal (man 7 signal)

        Signal     Value     Action   Comment
       ----------------------------------------------------------------------
       SIGHUP        1       Term    Hangup detected on controlling terminal
                                     or death of controlling process
       SIGINT        2       Term    Interrupt from keyboard
       SIGQUIT       3       Core    Quit from keyboard
       SIGILL        4       Core    Illegal Instruction
       SIGABRT       6       Core    Abort signal from abort(3)
       SIGFPE        8       Core    Floating point exception
       SIGKILL       9       Term    Kill signal
       SIGSEGV      11       Core    Invalid memory reference
       SIGPIPE      13       Term    Broken pipe: write to pipe with no
                                     readers
       SIGALRM      14       Term    Timer signal from alarm(2)
       SIGTERM      15       Term    Termination signal
       SIGUSR1   30,10,16    Term    User-defined signal 1
       SIGUSR2   31,12,17    Term    User-defined signal 2
       SIGCHLD   20,17,18    Ign     Child stopped or terminated
       SIGCONT   19,18,25    Cont    Continue if stopped
       SIGSTOP   17,19,23    Stop    Stop process
       SIGTSTP   18,20,24    Stop    Stop typed at tty
       SIGTTIN   21,21,26    Stop    tty input for background process
       SIGTTOU   22,22,27    Stop    tty output for background process

       The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

 

3 Linux-C开源学习

3.1 libevent

      libevent源码深度分析: http://blog.csdn.net/sparkliang/article/details/4957667

 

4 c 最佳实践

1)头文件不能有变量的定义,只能有申明。

2)  对于一个char*类型的buf,分别读出指定的int、long,方法:int i = *(int*)buf[0]; long l = *(long*)buf[4]

3) gdb core.file出现很多问号"??",导致无法定位函数?

    原因:首先看编译选项加-g,如果还有,用如下方法:

    1)gdb exe,进入gdb后执行:core-file core.15839;

    2)gdb core.15893,进入gdb后执行:file exe;

    注:exe是可执行文件。

4) cscope 文件构建: 对于c++需要使用full path

find /home/fishermen/works/intrest/tair -name "*.h" -o -name "*.c" -o -name "*.cpp" > cscope.files

cscope -bkq -i cscope.files

 5) ctags 生成c++辅助查询文件

ctags -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ --file-scope=yes --langmap=c:+.h:+.hpp:+.cpp --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q -R

7)make

http://www.ruanyifeng.com/blog/2015/02/make.html

 

5 知识点:

1)__attribute__属性详解

http://blog.csdn.net/ruixj/article/details/4274721

 

2))epoll模型下,什么时候触发EPOLLOUT、EPOLLIN事件?

在LT模式下,如果注册了epollout,只要socket可写(写缓冲未满),就会触发epollout;

在ET模式下,如果注册了epollin,只有当socket由不可写变为可写的时候,才会触发epollout;

在LT模式下,如果注册了epollin,只要socket可读(读缓冲有数据),就会触发epollin;

在ET模式下,如果注册了epollin,只有socket由不可读变为可读的时候,才会触发epollin;

 

 

6 性能分析工具

1)gperftools

 http://code.google.com/p/gperftools

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。