随笔分类 - 【01】linux编程
摘要:结构体buffer_head原理 struct buffer_head { unsigned long b_state; /* buffer state bitmap (see above) */ struct buffer_head *b_this_page;/* circular list of
阅读全文
摘要:union原理分析 示例 #include <stdio.h> typedef enum { RW_CTX_AB, RW_CTX_C, } rw_ctx_type_t; typedef struct rw_context { rw_ctx_type_t type; union { struct {
阅读全文
摘要:结构体赋值 C 语言的结构体部分初始化规则:当使用指定成员初始化(designated initializer)时,未初始化的成员会自动初始化为 0。 也就是说: struct readahead_control rac = { .file = f, .mapping = m, ._index =
阅读全文
摘要:函数posix_memalign 函数posix_memalign原型: #include <stdlib.h> int posix_memalign(void **memptr, size_t alignment, size_t size); 参数说明 memptr: 双重指针,用于存储分配的内存
阅读全文
摘要:rename函数 参考资料 1. rename函数解析
阅读全文
摘要:文件加锁 1. 例子 #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> void lock_set(int fd, int type) { struct flock lock; lock.l_w
阅读全文
摘要:参考资料 1. 使用backtrace获取堆栈信息 2. How to print a stack trace whenever a certain function is called
阅读全文
摘要:函数__atomic_compare_exchange_n 1. 函数原型: bool __atomic_compare_exchange_n (type *ptr, type *expected, type desired, bool weak, int success_memorder, int
阅读全文
摘要:syscall函数 系统调用号 函数名 入口点 源码 0 read sys_read fs/read_write.c 1 write sys_write fs/read_write.c 2 open sys_open fs/open.c 3 close sys_close fs/open.c 4 s
阅读全文
摘要:函数fmemopen、函数open_memstream 1. open_memstream函数原型: #include <stdio.h> FILE *open_memstream(char **ptr, size_t *sizeloc); 2. fmemopen函数原型: #include <st
阅读全文
摘要:pipe 参考资料 1. Linux - pipe() 管道的使用
阅读全文
摘要:参考资料 linux之pthread_atfork()函数讲解
阅读全文
摘要:__thread Thread Local Storage:线程局部存储(tls)分配的变量,每个当前线程有一个该变量的实例。__thread是gcc内置的线程局部存储设施,其存储效率可以和全局变量相比;__thread变量在每一个线程中都有一份独立实例,各线程值是互不干扰的。可以用来修饰那些带有全
阅读全文
摘要:_atomic系列函数 type __atomic_fetch_xxx(type *ptr, type val, int memorder) 参数说明: ptr:要操作的变量地址 val:参与运算的值 memorder:内存序(Memory Order),控制内存屏障语义 返回值:操作前的旧值 参考
阅读全文
摘要:gcc内置原子操作 从GCC4.1.版本之后就引入了内置的原子操作函数,可对x86_64架构(除此之外还有其他类型)1、2、4、8字节的integer scalar或pointer使用,可有效减少对锁机制的使用进一步而提升效率,这些函数以__sync开头,而在GCC4.7之后的版本,这些函数被替换成
阅读全文
摘要:gethostname、gethostbyname 函数解析 #include <stdio.h> #include <sys/socket.h> #include <netdb.h> #include <unistd.h> #include <netinet/in.h> #include <arp
阅读全文
摘要:一个 D-Bus 程序 /* 服务端代码 */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <dbus/dbus.h> void listen_signal() { D
阅读全文
摘要:va_start和va_end使用详解 函数参数是以数据结构:栈的形式存取,从右至左入栈。首先是参数的内存存放格式:参数存放在内存的堆栈段中,在执行函数的时候,从最后一个开始入栈。因此栈底高地址,栈顶低地址,例如: void func(int x, float y, char z); 调用函数的时候
阅读全文
摘要:alarm函数 1. 简介设置定时器(闹钟)。在指定seconds后,内核会给当前进程发送 14)SIGALRM信号,进程收到信号后,默认动作终止。 每个进程都有且只有唯一个定时器。 2. alarm函数原型: unsigned int alarm(unsigned int seconds); 常用
阅读全文
摘要:kill函数 1. 函数原型 int kill(pid_t pid, int signo); //signo:信号名 分析: 注意: 进程组:每个进程都属于一个进程组,进程组是一个或多个进程的集合, 它们相互关联,共同完成一个实体任务。每个进程组都有一个进程组长,默认进程组ID与进程组长ID相同。权
阅读全文

浙公网安备 33010602011771号