基本的终端接口
接口特性
当一个终端文件被打开,通常它将引起进程等待直到连接被建立
进程组
一个终端可以具有与它相关的前台进程组,它发挥特定的角色
可设置的参数
termios 机构
该结构在<termios.h>中定义,在控制特定的终端 I/O 特性中要用到
输入模式
termios c_iflap 值域
| 标记名 | 描述 |
| BRKINT | 信号中断 |
| ICRNL | 输入时将CR映射到NL |
| IGNBRK | 忽略中断状态 |
| IGNCR | 忽略CR |
| IGNPAR | 忽略奇偶错误 |
| INLCR | 输入时将NL映射到CR |
| INPCK | 输入奇偶校验使能 |
| ISTRIP | Strip字符 |
| IXOFF | 开始/停止输入控制使能 |
| IXON | 开始/停止输出控制使能 |
| PARMRK | 产生奇偶错误 |
控制模式
| 标记名 | 描述 |
| CLOCAL | 忽略modem状态行 |
| CREAD | 接收使能 |
| CSIZE | 每个字节的位数 |
| CS5 | 5位 |
| CS6 | 6位 |
| CS7 | 7位 |
| CS8 | 8位 |
| CSTOPB | 发送一个或 俩个停止位 |
| HUPCL | 在最后的关闭中挂起 |
| PARENB | 奇校验使劲 |
| PARODD | 奇校验或 偶校验 |
本地模式
termios c_lflag 值
| 标识名 | 描述 |
| ECHO | 响应使能 |
| ECHOE | 响应ETASE |
| ECHOK | 响应KILL |
| ECHONL | 响应‘\n’ |
| ICANON | 规范输入 |
| IEXTEN | 扩展函数使能 |
| ISIG | 信号使能 |
| NOFLSH | 中断,停止或挂起后关闭flush |
| TOSTOP | 为后台输出发送SIGTTOU |
特殊的控制字符
这些特殊的控制字符值在队列 c_cc 中定义,分为规范和非规范两种模式
波特率函数
#include <termios.h>
//这些接口被用来在 termios 结构获得和设定输入与输出的波特率值
speed_t cfgetospeed(const struct termios *termios_p);
int cfsetospeed(struct termios *termios_p, speed_t speed);
speed_t cfgetispeed(const struct termios *termios_p);
int cfsetispeed(struct termios *termios_p, speed_t speed);
基本的终端接口控制函数
获得并设定状态
#include <termios.h>
//tcgetattr: 获得 fildes 所确定的文件的参数并将其存储在 termios_p 所指向的结构中
//tcsetattr:将设置参数
int tcgetattr(int fildes, struct termios *termios_p);
int tcsetattr(int fildes, int optional_actions, const struct termios *termios_p); 行控制函数
#include <termios.h>
//终端使用异步连续数据传输
//tcsendbreak: 引起在一段时间内连续的‘0’位传输
//tcdrain:等待直到输出传输完毕
//tcflush和 tcflow :溢出的相关处理
int tcsendbreak(int fildes, int duration);
int tcdrain(int fildes);
int tcflush(int fildes, int queue_selector);
int tcflow(int fildes, int action); 取得前台进程组的 ID
#include <sys/types.h>
pid_t tgetpgrp(int fildes); 设置前台进程组 ID
#include <sys/types.h>
//进程支持控制终端,该函数设置与终端相关的前台进程组 ID 到 pgrp_id
int tcsetpgrp(int fildes, pid_t pgrp_id);

京公网安备 11010502036488号