1. 调试

看见了一个好厉害的 blog ( https://eternalsakura13.com/

调试

本地能通,但是远程不行,最后发现是和 read 函数在不同情况下的读取的行为有关系。在 terminal 的时候,一行的内容超过了指定的大小,多余的内容会被抛弃。参考

If read () is reading from a terminal in canonical/cooked mode, the tty driver provides data a line at a time. So if you tell read () to get 3 characters or 300, read will hang until the tty driver has seen a newline or the terminal’s defined EOF key, and then read () will return with either the number of characters in the line or the number of characters you requested, whichever is smaller.