FDステータスフラグfcntl
を_ stdout と stderr の状態フラグも に変更されました。stdin
stdin
O_NONBLOCK
O_NONBLOCK
fcntl
関数、SYSCALL_DEFINE3
およびのソース コードを調べましたdo_fcntl
が、何も役に立ちませんでした。また、スタックオーバーフローまたはグーグル。カーネルまたはglibcの実装に関連している可能性があると思います。
私のコンピューターは、x86_64 上の Ubuntu 12.04 で、gcc 4.6.3 がインストールされています。
int flag = 0;
int value = O_NONBLOCK;
int fd = open("./tmp", O_RDONLY);
if(-1 == (flag = fcntl(fd, F_GETFL)))
fprintf(stdout, "%d:%s\n", errno, strerror(errno));
flag = fcntl(stdin->_fileno, F_GETFL);
flag = fcntl(stderr->_fileno, F_GETFL);
if(-1 == (flag = fcntl(stdout->_fileno, F_GETFL)))
fprintf(stdout, "%d:%s\n", errno, strerror(errno));
flag = fcntl(stdout->_fileno, F_SETFL, flag | O_NONBLOCK);
flag = fcntl(fd, F_GETFL);
flag = fcntl(stdin->_fileno, F_GETFL);
flag = fcntl(stdout->_fileno, F_GETFL);
flag = fcntl(stderr->_fileno, F_GETFL);
flag = fcntl(stdin->_fileno, F_SETFL, flag | O_APPEND);
flag = fcntl(fd, F_GETFL);
flag = fcntl(stdin->_fileno, F_GETFL);
flag = fcntl(stdout->_fileno, F_GETFL);
flag = fcntl(stderr->_fileno, F_GETFL);
close(fd);
これは、この問題に対する私のコードです。