#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(void)
{
int fd;
char str[10];
close(STDOUT_FILENO);
fd = open("./test.c", O_RDONLY);
if (fd < 0)
{
perror("Open");
exit(1);
}
sprintf(str, "fd = %d\n", fd);
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(void)
{
int fd;
char str[10];
close(STDOUT_FILENO);
fd = open("./test.c", O_RDONLY);
if (fd < 0)
{
perror("Open");
exit(1);
}
sprintf(str, "fd = %d\n", fd);
write(STDERR_FILENO, str, strlen(str)+1);
return 0;
![](https://img-my.csdn.net/uploads/201612/08/1481201471_6133.png)