信号EOF在Mac OSX上终端 [英] Signal EOF in mac osx terminal

查看:1951
本文介绍了信号EOF在Mac OSX上终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在K&AMP中的1.5.2的问题难住了; R。我GOOGLE了一段时间并发现我有进入字符后,供应EOF输入。

I am stumped by the 1.5.2 question in K&R. I googled for sometime and found out that i have to supply the EOF input after entering the characters.

long nc = 0;

while (getchar() != EOF)
    ++nc;
printf("%ld\n", nc);

return 0;

我都尝试commnad-D和控制-D作为EOF输入,但毫无效果。任何想法如何为Mac OSX提供EOF?

I tried both commnad-D and control-D as EOF inputs but nothing worked. Any Idea how to supply the EOF for mac osx?

推荐答案

默认情况下,Mac OS X(以前的Mac OS X)终端识别EOF时控制-D是在一行的开头pssed $ P $

By default, OS X (formerly Mac OS X) terminals recognize EOF when control-D is pressed at the beginning of a line.

在详细地说,在实际操作是,当控制-D是pressed,在终端的输入缓冲器中的所有字节使用该终端被发送到正在运行的进程。在一行的开头,不字节是在缓冲区中,所以这个过程被告知有零字节可用,并且这作为一个EOF指示器

In detail, the actual operation is that, when control-D is pressed, all bytes in the terminal’s input buffer are sent to the running process using the terminal. At the start of a line, no bytes are in the buffer, so the process is told there are zero bytes available, and this acts as an EOF indicator.

这个过程兼作线年底前交付输入过程的方法:用户可以输入一些字符,preSS控制-D,字符将被立即发送到进程,而不通常等待输入/回报是pressed。执行这个立即发送所有缓冲的字节的操作后,没有字节被留在缓冲器中。所以,当控制-D是pressed的第二时间,它是相同的一个线的开头(没有字节被发送,并且处理被赋予零字节),它的作用就像一个EOF

This procedure doubles as a method of delivering input to the process before the end of a line: The user may type some characters and press control-D, and the characters will be sent to the process immediately, without the usual wait for enter/return to be pressed. After this "send all buffered bytes immediately" operation is performed, no bytes are left in the buffer. So, when control-D is pressed a second time, it is the same as the beginning of a line (no bytes are sent, and the process is given zero bytes), and it acts like an EOF.

您可以通过在终端使用命令男子4 TTY了解更多关于终端的行为。默认的行纪律的termios。您可以通过使用命令男人的termios了解更多有关termios的线路规范。

You can learn more about terminal behavior by using the command "man 4 tty" in Terminal. The default line discipline is termios. You can learn more about the termios line discipline by using the command "man termios".

这篇关于信号EOF在Mac OSX上终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆