先看下面一段代码:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>int main(){int fd = open("/home/lrao/test", O_CREAT | O_RDWR | O_APPEND,S_IRWXU|S_IRWXG|S_IRWXO) ;close(1) ;int w = dup(fd) ;printf("hello");write(fd,"\r\nwrite\r\n",9);close(fd);return 0;
}
ca t/home/lrao/test 查看内容如下:
<空行>
write
hello
会有这样的现象,printf先运行,后写入