文件描述符fd
通过对 open 函数的理解,可见文件描述符是一个小整数
执行以下代码,看看你能发现什么:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
int fd0 = open ("./log.txt", O_WRONLY | O_CREAT , 0644);
int fd1 = open ("./log.txt", O_WRONLY | O_CREAT , 0644);
int fd2 = open ("./log.txt", O_WRONLY | O_CREAT , 0644);
int fd3 = open ("./log.txt", O_WRONLY | O_CREAT , 0644);
printf("fd0: %d\n",fd0);
printf("fd1: %d\n",fd1);
printf("fd2: %d\n",fd2);
printf("fd3: %d\n",fd3)