Output of Function Set By signal() Delayed
From: Leo Wong (gnow_oel_at_hotmail.com)
Date: 08/26/04
- Next message: Felix Tilley: "Re: Euler-Mascheroni Constant"
- Previous message: Last2Know: "Re: cygwin DLLs"
- Next in thread: Paul Pluzhnikov: "Re: Output of Function Set By signal() Delayed"
- Reply: Paul Pluzhnikov: "Re: Output of Function Set By signal() Delayed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Aug 2004 20:45:20 -0700
QUESTION
--------
I ran the program below on the latest Debian Linux. When I pressed
Ctrl-C, "interrupt" printed, but the new prompt '%' did not appear
until I entered RETURN. Then I changed the line
printf("interrupt\n%% ");
in function sig_int to
fprintf(stderr, "interrupt\n%% ");
and reran the program, every thing was OK; the prompt '%' printed
immediately.
Thanks in advance for explaining me why this happend.
COPY of THE CODES
-----------------
/* p.18, program 1.8,
* Advanced Programming in the UNIX Environment
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include "ourhdr.h"
static void sig_int(int);
int
main(void)
{
char buf[MAXLINE];
pid_t pid;
int status;
if (signal(SIGINT, sig_int) == SIG_ERR)
err_sys("signal error");
printf("%% ");
while(fgets(buf, MAXLINE, stdin) != NULL) {
buf[strlen(buf) - 1] = 0;
if ( (pid = fork()) < 0)
err_sys("fork error");
else if (pid == 0) {
execlp(buf, buf, (char *) 0);
err_ret("couldn't execute: %s", buf);
exit(127);
}
if ( (pid = waitpid(pid, &status, 0)) < 0)
err_sys("waitpid error");
printf("%% ");
}
exit(0);
}
void
sig_int(int signo)
{
printf("interrupt\n%% "); /**/
}
- Next message: Felix Tilley: "Re: Euler-Mascheroni Constant"
- Previous message: Last2Know: "Re: cygwin DLLs"
- Next in thread: Paul Pluzhnikov: "Re: Output of Function Set By signal() Delayed"
- Reply: Paul Pluzhnikov: "Re: Output of Function Set By signal() Delayed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|