![`cat`을 종료하려면 왜 ^D를 두 번 눌러야 합니까? [복사]](https://linux55.com/image/115082/%60cat%60%EC%9D%84%20%EC%A2%85%EB%A3%8C%ED%95%98%EB%A0%A4%EB%A9%B4%20%EC%99%9C%20%5ED%EB%A5%BC%20%EB%91%90%20%EB%B2%88%20%EB%88%8C%EB%9F%AC%EC%95%BC%20%ED%95%A9%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
실행 cat
하고 입력 a
해 보겠습니다. 종료되지 않는 ^D
것을 볼 수 있습니다 .cat
cat
+++와 비교해 보세요 a
. 이제 고양이가 종료됩니다.Enter
^D
그렇다면 왜 첫 번째 경우에는 두 번 눌러야 종료되지만 ^D
두 번째 경우에는 한 번만 눌러야 할까요?cat
^D
답변1
대답은 termios(3)
매뉴얼 페이지에서 찾을 수 있습니다:
VEOF (004, EOT, Ctrl-D) End-of-file character (EOF). More precisely:
this character causes the pending tty buffer to be sent to the
waiting user program without waiting for end-of-line. If it is
the first character of the line, the read(2) in the user program
returns 0, which signifies end-of-file. Recognized when ICANON
is set, and then not passed as input.
처음 누르는 키는 ^D
입력한 줄을 에 전송하므로 결과를 cat
얻습니다 (한 문자, EOL 문자 없음). 두 번째 결과는 0을 반환하며 이는 EOF에 도달했음을 나타냅니다 .read(2)
a
^D
read(2)
cat