C++ Linux Notes

  1. the return value of pthread_equal()

RETURN VALUE
If the two thread IDs are equal, pthread_equal() returns a nonzero
value; otherwise, it returns 0.

  1. GDB debug
    step into (s)
    next step (n)
    backward to caller function (finish)
  • gdb gui
    gdb -tui testServer
    also Ctrl-x Ctrl-a after run gdb

http://www.gnu.org/software/gdb/links/
https://sourceware.org/insight/screenshots.php

  1. gcc编译参数-fPIC的一些问题
    -fPIC 作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),则产生的代码中,没有绝对地址,全部使用相对地址,故而代码可以被加载器加载到内存的任意位置,都可以正确的执行。这正是共享库所要求的,共享库被加载时,在内存的位置不是固定的.
    如果不加-fPIC,则加载.so文件的代码段时,代码段引用的数据对象需要重定位, 重定位会修改代码段的内容,这就造成每个使用这个.so文件代码段的进程在内核里都会生成这个.so文件代码段的copy.

  2. Cmake的 debug和release
    cmake -DCMAKE_BUILD_TYPE=Debug/Release path
    https://stackoverflow.com/questions/7724569/debug-vs-release-in-cmake
    https://my.oschina.net/u/4000302/blog/3059013

  3. 函数名称:unlink
    头文件:unistd.h(在WIN32系统中为windows.h)
    函数功能:删除一个文件的目录项并减少它的链接数,若成功则返回0,否则返回-1,错误原因存于error。如果想通过调用这个函数来成功删除文件,你就必须拥有这个文件的所属目录的写和执行权限。

'#include<unistd.h> '
'#include<stdio.h>'
int main(void)
{
FILE *fp = fopen("junk.jnk","w");
int status;
fprintf(fp,"junk");
status = access("junk.jnk",0);
if (status == 0)
printf("File exists\n");
else
printf("File doesn't exist\n");
fclose(fp);
unlink("junk.jnk");
status = access("junk.jnk",0);
if (status == 0)
printf("File exists\n");
else
printf("File doesn't exist\n");
return 0;
}

  1. hexdump
posted @ 2019-11-24 11:29  Saymour2008  阅读(38)  评论(0编辑  收藏  举报