#include
#include
#include
#include
#include
#include
#include
#define BUFFSIZE 100
void
sig_alrm(int signo)
{
return;
}
int main(int argc, char *argv[])
{
int fd[2], n,;
pid_t pid;
char buf[BUFFSIZE];
if (pipe(fd) < 0)
perror("pipe error!\n");
if ((pid = fork()) < 0)
perror("fork error\n");
else if (pid > 0) {
close(fd[0]);
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(fd[1], buf, n) != n)
perror("write error");
close(fd[1]);
kill(pid, SIGALRM);
if (waitpid(pid, NULL, 0) < 0)
perror("wait error\n");
exit(0);
}
else {
signal(SIGALRM, sig_alrm);
sleep(20);
close(fd[1]);
while ((n = read(fd[0], buf, BUFFSIZE)) > 0) {
if (write(STDOUT_FILENO, buf, n) != n)
perror("write error\n");
exit(0);
}
}
}
阅读(1163) | 评论(0) | 转发(0) |