-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy path10.21.c
More file actions
37 lines (27 loc) · 656 Bytes
/
10.21.c
File metadata and controls
37 lines (27 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "apue.h"
#define BUFFSIZE 1024
static void sig_tstp(int signo) {
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGTSTP);
sigprocmask(SIG_UNBLOCK, &mask, NULL);
signal(SIGTSTP, SIG_DFL);
kill(getpid(), SIGTSTP);
signal(SIGTSTP, sig_tstp);
}
int main() {
int n;
char buf[BUFFSIZE];
if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
signal(SIGTSTP, sig_tstp);
}
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) {
if (write(STDOUT_FILENO, buf, n) != n) {
err_sys("write error");
}
}
if (n < 0) {
err_sys("read error");
}
exit(0);
}