File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <signal.h>
4
+ #include <unistd.h>
5
+
6
+
7
+ #define BUFFSIZE 1024
8
+
9
+ static void sig_tstp (int );
10
+
11
+ int main (void )
12
+ {
13
+ int n ;
14
+ char buf [BUFFSIZE ];
15
+
16
+ if (signal (SIGTSTP , SIG_IGN ) == SIG_DFL ) {
17
+ signal (SIGTSTP , sig_tstp );
18
+ }
19
+
20
+ while ((n = read (STDIN_FILENO , buf , BUFFSIZE )) > 0 ) {
21
+ if (write (STDOUT_FILENO , buf , n ) != n ) {
22
+ printf ("write error\n" );
23
+ exit (-1 );
24
+ }
25
+ }
26
+
27
+ if (n < 0 ) {
28
+ printf ("read error\n" );
29
+ exit (-1 );
30
+ }
31
+
32
+ return 0 ;
33
+ }
34
+
35
+ static void sig_tstp (int signo )
36
+ {
37
+ sigset_t mask ;
38
+
39
+ sigemptyset (& mask );
40
+ sigaddset (& mask , SIGTSTP );
41
+ sigprocmask (SIG_UNBLOCK , & mask , NULL );
42
+
43
+ signal (SIGTSTP , SIG_DFL );
44
+
45
+ kill (getpid (), SIGTSTP );
46
+
47
+ signal (SIGTSTP , sig_tstp );
48
+ }
You can’t perform that action at this time.
0 commit comments