-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.c
More file actions
39 lines (38 loc) · 756 Bytes
/
read.c
File metadata and controls
39 lines (38 loc) · 756 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
38
39
/*************************************************************************
> File Name: read.c
> Author: jianghechao
> Mail: 591378033@qq.com
> Created Time: Tue 06 May 2014 06:47:18 PM CST
************************************************************************/
#include<stdio.h>
#include"apue.h"
#define MAXLINE 100
#include<signal.h>
static void sig_alrm(int signo)
{
switch(signo)
{ case SIGALRM:
printf("SIGALRM signal received\n");
break;
default:
break;
}
}
int main()
{
int n;
char line[MAXLINE];
if(signal(SIGALRM,sig_alrm)==SIG_ERR)
{
perror("signal error");
}
alarm(10);
if(n=read(STDIN_FILENO,line,MAXLINE)<0)
{
perror("read error");
}
//clear the alarm
alarm(0);
write(STDOUT_FILENO,line,n);
return 0;
}