Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <signal.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <errno.h>
- static sig_atomic_t exitflag = 0;
- static void interrupt(int sig)
- {
- exitflag = 1;
- }
- int main()
- {
- struct sigaction sa;
- sigaction(SIGHUP, NULL, &sa);
- sa.sa_handler = interrupt;
- sa.sa_flags &= ~SA_RESTART;
- sigaction(SIGHUP, &sa, NULL);
- while (!exitflag) {
- char buf[1024];
- int l = read(0, buf, sizeof(buf));
- if (l == -1) {
- if (errno == EINTR || errno == EAGAIN) {
- perror("read");
- continue;
- }
- break;
- } else if (l == 0) {
- break;
- }
- write(1, buf, l);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement