在linux下的文件缓存输出机制
1、缓存已满内容输出
2、按照”\n”格式化打印输出
3、进程结束
4、STDERR的输出优先级大于STDOUT,而且STDERR不可以被重定向。[命令除外 2>&1 ]
关于linux下的dup()和dup2()
dup()重定向
int dup(int oldfd);
dup(): uses the lowest-numbered unused descriptor for the new descriptor.以后就可以通过返回的文件描述符操作文件。
dup2()重定向
int dup2(int oldfd, int newfd);
dup2() makes newfd be the copy of oldfd, closing newfd first if neces‐sary, but note the following:
If oldfd is not a valid file descriptor, then the call fails, and newfd is not closed.
If oldfd is a valid file descriptor, and newfd has the same value as
oldfd, then dup2() does nothing, and returns newfd.
dup2()可以通过把newfd的文件描述符返回给指定的文件描述符来重定向到oldfd中。