2017-04-06 77 views
0

在我的終端,如果我運行,getchar()如何在內部工作?

> tty 
/dev/tty0 
> ./myprogram.out 

在我的程序有getchar(),則對從/dev/tty0文件等待輸入stdin(0)文件描述符塊。

這個過程也通過流程管理基礎上,它得到的時間片調度。

我的問題是,

如何getchar()伺候stdingetchar()內部用於等待stdin上的輸入的系統調用是什麼?

+0

有幾個問題已經涉及到這一點。例如http://stackoverflow.com/questions/9544151/how-getchar-is-implemented或http://stackoverflow.com/questions/32131873/equivalent-of-fgetc-with-unix-file-descriptors。 –

+0

您可以使用'strace'來查看程序所做的所有系統調用。 – aschepler

+1

Matteo Italia的答案可能就像你想要解決這個問題一樣。任何進一步的,你[處理TTY的東西](https://i.stack.imgur.com/YRt4W.png)。 –

回答

3

最可能的是,當讀緩衝器爲空的純阻斷read在FD與C流stdin相關聯,來執行。