首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Linux上C编程: Knowledge Points

2012-07-19 
Linux下C编程: Knowledge Points1. struct timeval:#include bits/time.hstruct timeval? {??? __time_t

Linux下C编程: Knowledge Points

1. struct timeval:

#include <bits/time.h>

struct timeval

? {

??? __time_t tv_sec;????????? /* Seconds.? */

??? __suseconds_t tv_usec;??? /* Microseconds.? */

? };

?

__time_t 是 long int 的宏定义

__suseconds_t 也是 long int的宏定义.

?

2.

stdin, stdout, stderr类型为 FILE*

STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO类型为 int

?

使用stdin的函数主要有:fread、fwrite、fclose等,是文件流方式。属于高级IO,带缓冲的。

使用STDIN_FILENO的函数有:read、write、close等, 属于低级IO,要自己处理缓冲。

?

STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO 定义在 <unistd.h>中,值分别是 0,1,2.

3. 线程

(1) 线程的终止:

????? 情况一:如果从 main() 函数中返回或者是调用了 exit() 函数退出主线程,则整个进程将终止,此时进程中的所有线程也将终止。

????? 情况二:主线程调用 pthread_exit()函数,那么仅仅是主线程消亡,进程不会终止,进程内的其他线程也不回终止,直到所有线程结束,进程才会终止。

?

热点排行