linux获取终端输入进程,Linux终端输入输出(termios)函数

本文详细介绍了Linux系统中用于控制终端输入输出的termios函数,包括tcgetattr, tcsetattr等,以及termios结构体的各个成员和标志常量,如输入模式、输出模式、控制模式和本地模式的标志。此外,还讨论了canonical和non-canonical模式、raw模式以及线控操作,如波特率设置和数据流控制。示例代码展示了如何获取标准输入终端的属性并切换到raw模式。" 51089240,1125819,Windows环境下node-webkit整合sqlite和socket的踩坑记录,"['node.js', 'sqlite', 'node-webkit', 'windows开发', '编程环境']
摘要由CSDN通过智能技术生成

termios系列函数-tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed等,用以获取/设置终端设备的属性/控制/速度。1. 函数声明

函数声明

#include #include /*获取文件描述符fd对应设备状态置入termios_p所指向结构体中*/

int tcgetattr(int fd, struct termios *termios_p);

/*设置文件描述符对应设备状态*/

int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);

/*向fd发送0比特*/

int tcsendbreak(int fd, int duration);

/*挂起直到所有写入fd的输出全部发送完毕*/

int tcdrain(int fd);

/*丢弃所有准备写入但还未发送给fd的数据或从fd已接收但还还未被读取的数据*/

/*丢弃对象取决于queue_selector*/

int tcflush(int fd, int queue_selector);

/*挂起fd发送操作或接收操作,挂起对象取决于action*/

int tcflow(int fd, int action);

/*设备终端属性*/

void cfmakeraw(struct termios *termios_p);

/*返回termios_p所指向结构体中的输入波特率*/

speed_t cfgetispeed(const struct termios *termios_p);

/*返回termios_p所指向结构体中的输出波特率*/

speed_t cfgetospeed(const struct termios *termios_p);

/*设置termios_p所指向结构体中的输入波特率*/

int cfsetispeed(struct termios *termios_p, speed_t speed);

/*设置termios_p所指向结构体中的输出波特率*/

int cfsetospeed(struct termios *termios_p, speed_t speed);

/*4.4BSD扩展,设置输入输出波特率*/

int cfsetspeed(struct termios *termios_p, speed_t speed);

glibc功能测试宏定义:

cfsetspeed(), cfmakeraw(): _BSD_SOURCE2. termios结构体

大多数termios函数都会用到termios结构。termios结构体定义如下:

·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150typedefunsignedcharcc_t;

typedefunsignedintspeed_t;

typedefunsignedinttcflag_t;

structtermios

{

tcflag_t c_iflag;       /* input mode flags */

tcflag_t c_oflag;       /* output mode flags */

tcflag_t c_cflag;       /* control mode flags */

tcflag_t c_lflag;       /* local mode flags */

cc_t c_line;            /* line discipline */

cc_t c_cc[NCCS];        /* control characters */

speed_t c_ispeed;       /* input speed */

speed_t c_ospeed;       /* output speed */

#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1

#define _HAVE_STRUCT_TERMIOS_C_OSPEED

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值