作者Knudsen (true me)
看板LinuxDev
標題[問題] 設定_IONBF失敗?
時間Tue Mar 16 16:40:50 2010
Hi,
我用 RS232 接到板子上印出一些東西, 因為 serial port tty 是 line buffered, 所以
我用 setvbuf+_IONBF 設成 no buffer, 所以若是我的程式裡面寫
printf("hello \n");
printf("world");
while(1) {
/* Wait for some event and exit */
}
"world" 是可以印出來的, 但是若寫成像
char *str = "beautiful";
printf("hello \n");
printf("world is %s", str);
while(1) {
/* Wait for some event and exit */
}
則 "beautiful" 還是要等到 while 裡面的事情做完才會印
可以給我提示怎麼解決嗎?
Thanks.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.209.21
1F:→ sunneo:直接把printf改為fprintf(stderr吧 03/26 03:38
2F:→ sunneo:歐..是line buf,那試試看用buf + iomap, 再以prot_read 03/26 03:41
3F:→ sunneo:用fflush來作為handler 03/26 03:42