浅析memcmp 和 strcmp
摘要:eg: #include <stdio.h> #include <string.h> int main(void) { char string[7] = "ABCDEFG"; char copy[4] = "ABCD"; int ret; ret = memcmp(string,copy,7); p
阅读全文
利用多个sem信号量在线程通讯
摘要:直接上代码,主要用到sem_trywait & sem_post #include<stdio.h> #include<pthread.h> #include<stdlib.h> #include<string.h> #include<semaphore.h> #include<time.h> se
阅读全文
sem信号量与死锁的边缘
摘要:1. 演示一个例子,出现死锁,用strace debug得到 #include<stdio.h> #include<pthread.h> #include<stdlib.h> #include<string.h> #include<semaphore.h> sem_t sem; typedef st
阅读全文
研究一种表驱动法的编程方式
摘要:#include <stdio.h> #include <string.h> typedef void (*func_evt_hdl)(); /*ptr*/ typedef struct _task_list_ { int flag; func_evt_hdl handler; }EVT_HDL_N
阅读全文
select 中的timeout
摘要:1. select 相关man 资料 /* According to POSIX.1-2001 */ #include <sys/select.h> /* According to earlier standards */ #include <sys/time.h> #include <sys/ty
阅读全文
ioctl以及read阻塞型引发的思考
摘要:1. 尝试strace 或 jstack 去追踪程序,发现某一个进程作为socket连接server出现如下的log(strace追踪): 1. ioctl(45,[0],0) = 0 2. ........ 3. ioctl(45,[12],0) = 12 ioctl作为用户态和内核态的数据交互,
阅读全文
用strace处理程序异常挂死情况
摘要:1. 环境: ubuntu 系统 + strace + vim 2.编写挂死程序:(参考博客) #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <string.h> int main(int argc, c
阅读全文