1、概述
•
终端的输入
/
输出队列
2、特殊的输入字符及stty命令
•
EOF ^D # end of file
•
KILL ^U # erase whole line
•
WERASE ^W # backspace one word
•
LNEXT ^V #
按照字面意思解释下一个字符,屏蔽其特殊含义
•
INTR ^C # interrupt signal
•
QUIT ^\ # quit signal
•
STOP ^S # stop output
•
START ^Q # resume output
•
SUSP ^Z # suspend signal
•
stty
命令:
•
stty
-a #
查看终端选项
•
stty
KILL ^b #
修改按键定义,命令执行时忽略参数的大小写
•
stty
kill ^B #
等价于上一个命令
3、终端窗口大小变更
•
终端窗口大小变更时,向前台进程组发送
SIGWINCH
信号
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <termios.h>
#ifndef TIOCGWINSZ
#include <sys/ioctl.h>
#endif
void err_sys(char *p)
{
perror(p);
exit(0);
}
static void pr_winsize(int fd)
{
struct winsize size;
if( ioctl(fd, TIOCGWINSZ, (char *) &size) < 0 )
err_sys("TIOCGWINSZ error");
printf("%d rows, %d columns\n", size.ws_row, size.ws_col);
}
static void sig_winch(int signo)
{
printf("SIGWINCH received\n");
pr_winsize(STDIN_FILENO);
}
int main(void)
{
if( isatty(STDIN_FILENO) == 0 )
exit(1);
if( signal(SIGWINCH, sig_winch) == SIG_ERR )
err_sys("signal error");
pr_winsize(STDIN_FILENO); /* print initial size */
for ( ;; ) /* and sleep forever */
pause();
}