Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1757231
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: C/C++

2012-02-18 15:52:30


  1. #include "apue.h"
  2. #define BUFFSIZE 1024
  3. static void sig_tstp(int );
  4. int main(void)
  5. {
  6.     int n;
  7.     char buf[BUFFSIZE];

  8.     /*
  9.      *Only catch sigtstp if we're running with a job-control shell
  10.      */
  11.     if (signal(SIGTSTP,SIG_IGN) == SIG_DFL)
  12.         signal(SIGTSTP,sig_tstp);
  13.     while( (n =read(STDIN_FILENO,buf,BUFFSIZE) ) > 0)
  14.         if (write(STDOUT_FILENO,buf,n) !=n )
  15.             err_sys("write error");
  16.     if (n < 0)
  17.         err_sys("read error");
  18.     exit(0);
  19. }
  20. static void
  21. sig_tstp(int signo)
  22. {
  23.     sigset_t mask;
  24.     /*
  25.      *...move cursor to lower left corner,reset tty mode ....
  26.      */
  27.     /*
  28.      *Unblock sigtstp,since it't block while we're handling it.
  29.      */
  30.     sigemptyset(&mask);
  31.     sigaddset(&mask,SIGTSTP);
  32.     sigprocmask(SIG_UNBLOCK,&mask,NULL);
  33.     signal(SIGTSTP,SIG_DFL);/* RESET disposition to default */
  34.     kill(getpid(),SIGTSTP); /* and send the signalto ourself */
  35.     /*
  36.      * we won't return form the kill until we're continued
  37.      */
  38.     signal(SIGTSTP,sig_tstp); /* reestablish signal handler */
  39.     /*
  40.      * reset tty mode,redraw window
  41.      *...................
  42.      */
  43. }

















阅读(1301) | 评论(0) | 转发(0) |
0

上一篇:DB2 --表空间

下一篇:apue signal summary-apue

给主人留下些什么吧!~~