(《科幻世界》杂志 2002年1月第1期)
“有一句话我早就想对你们说,”丁仪对妻子和女儿说,“我心中位置大部分都被物理学占据了,只是努力挤出了一个小角落给你们。对此我心里很痛苦,但也实在是没办法。”
他的妻子方琳说:“这话你对我说过两百遍了。”
十岁的女儿文文说:“对我也说过一百遍了。”
丁仪摇摇头说:“可你们始终没能理解我这话的真正含义,你们不懂得物理学到底是什么。”
方琳笑着说:“只要它的性别不是女的就行。”
这里,他们一家三口正坐在一辆时速达五百公里的小车上,行驶在一条直径5米的钢管中,这根钢管的长度约为三万公里,在北纬45度线上绕地球一周。
c11 标准中增加了多线程支持
c// 创建线程
typedef unsigned long int thrd_t;
int thrd_create(thrd_t *__thr,thrd_start_t __func,void *__arg);
/*
__thr 线程id的指针
__func 接受 void * 参数的函数指针,返回值为 int 类型
__arg 传递给 __func 的参数
*/
// 判断是否同一线程
int thrd_equal (thrd_t __lhs, thrd_t __rhs);
// 返回当前线程 id
thrd_t thrd_current (void);
// 至少阻塞线程 __time_point 时间。阻塞期间线程可能会收到信号恢复执行,
// 此时如果 __remaining 非空,则剩余时间会存储到 __remaining 中
int thrd_sleep (const struct timespec *__time_point,
struct timespec *__remaining);
// 终止当前线程,清理所有线程私有数据并释放资源。返回在 __res 中指定的值。
void thrd_exit (int __res) __attribute__ ((__noreturn__));
// 分离线程
int thrd_detach (thrd_t __thr);
// 阻塞当前线程直到 __thr 线程结束。
// 如果 __res 非空,会存储 __thr 线程的返回值
int thrd_join (thrd_t __thr, int *__res);
// 当前线程声明可以主动让出 cpu 资源
// 停止当前线程的执行,并由系统调度程序来决定下一个执行哪个线程。
// 系统调度程序可以选择当前线程以保持运行。
void thrd_yield (void);
c#include <pthread.h>
int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
/*
1. 功能
创建新线程
2. 参数
pthread_t *tid, 线程id,用来标识线程
pthread_attr_t *attr, 线程属性(下文详述)
一个接收 void * 参数的函数指针
传递给 start_routine 的参数
3. 返回
成功返回0,失败返回错误码
*/
c// 打开文件
FILE *fopen(const char *pathname, const char *mode);
/*
mode 可选
r 读文件,文件指针位置为文件开始
r+ 读写文件,文件指针位置为文件开始
w 写文件,文件存在则清空文件,不存在则创建文件
w+ 读写文件,文件存在则清空文件,不存在则创建文件
a 追加文件,文件指针位置为文件结尾,文件不存在则创建
a+ 读取和追加文件,文件不存在则创建。输出总是追加到文件末尾。对于glibc,读取的初始文件位置在文件的开头,但是对于Android/BSD/MacOS,读取的初始文件位置在文件的结尾。
rb,rb+,wb,wb+,ab,ab+ 表示以二进制打开文件
*/
// 关闭文件
int fclose(FILE *stream);
| pcap 文件头 | 数据包头 | 数据包 | 数据包头 | 数据包 | ......
1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 0 | magic_numver | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4 | major_version | minor_version | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 8 | thiszone | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 12 | sigfigs | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 16 | snaplen | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 20 | linktype | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+