設備和麪向類的函數 基本的終端接口 termios  termios 機構 取得前臺進程組的 ID 設置前臺進程組 ID 行控制函數 獲得並設定狀態 接口特性 波特率函數 基本的終端接口控制函數

基本的終端接口

    接口特性

          當一個終端文件被打開,通常它將引起進程等待直到連接被建立

          進程組

            一個終端可以具有與它相關的前臺進程組,它發揮特定的角色

    可設置的參數

          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);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章