你是怎么做到用C非阻塞控制台I / O在Linux上? [英] How do you do non-blocking console I/O on Linux in C?

查看:335
本文介绍了你是怎么做到用C非阻塞控制台I / O在Linux上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何用C的Linux / OS X做非阻塞IO控制台?

How do you do nonblocking console IO on Linux/OS X in C?

推荐答案

您不这样做,真的。该TTY(控制台)是pretty有限的设备,并pretty多不做非阻塞I / O。当你看到的东西,看起来像你做什么非阻塞I / O,说在诅咒/ ncurses的应用程序,被称为的原始I / O 的。在原始I / O,还有人物的无间pretation,没有擦除处理等相反,你需要编写自己的code,对于数据的检查,同时做其他的事情。

You don't, really. The TTY (console) is a pretty limited device, and you pretty much don't do non-blocking I/O. What you do when you see something that looks like non-blocking I/O, say in a curses/ncurses application, is called raw I/O. In raw I/O, there's no interpretation of the characters, no erase processing etc. Instead, you need to write your own code that checks for data while doing other things.

在现代的C程序,可以简化这个另一种方式,通过将主机I / O成的线程的或轻量级进程。然后将I / O可以继续以通常的阻挡方式,但数据可被插入到一个队列被另一个线程上处理。

In modern C programs, you can simplify this another way, by putting the console I/O into a thread or lightweight process. Then the I/O can go on in the usual blocking fashion, but the data can be inserted into a queue to be processed on another thread.

下面是一个诅咒,覆盖更教程

这篇关于你是怎么做到用C非阻塞控制台I / O在Linux上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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