⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terminal.c

📁 linux下基于网络编程的TCP/IP端控制开发源程序
💻 C
字号:
#include<termios.h>#include<stdio.h>#include<sys/signal.h>struct termios old_save;void error_quit(char *err_string){    fprintf(stderr,"%s\n",err_string);   exit(1);} void change_mode(void) {  struct termios new_term;  if(!isatty(0))   error_quit("standard input is not a terminal");    if(tcgetattr(0,&new_term)==-1)   error_quit("get the attributes of the terminal");   old_save=new_term;   new_term.c_lflag&=~ISIG;   if(tcsetattr(0,TCSANOW,&new_term)==-1)      error_quit("set new terminal attributes"); }void restore_mode(void) {   if( tcsetattr(0,TCSANOW,&old_save)==-1)            error_quit("restore terminalattributes"); }void handle_ctrl_c(int signo)  {      printf("the process receive SIGINT signle number=%d\n",signo);      printf("now the process will change its terminal attributes.\n");      change_mode();   }void handle_term_signal(int signo)  {      printf("signle number=%d\n",signo);      printf("the process will restore its terminal attributes and exit\n");      restore_mode();     exit(0);   }main(int argc,char **argv)  {    signal(SIGINT,handle_ctrl_c);    signal(SIGTERM,handle_term_signal);    printf("please press the buttons ctrl+c\n");    for(;;);  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -