Message116538
The following minimal C code shows how EINTR can be handled:
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#define BUFFER_SIZE 1024
int
main()
{
char buffer[BUFFER_SIZE];
printf("PID = %d\n", getpid());
while (1) {
int rv = fgetc(stdin);
if (rv < 0) {
if (feof(stdin))
break;
if (errno == EINTR)
continue;
printf("Call failed with %d\n", errno);
return 1;
}
else
fputc(rv, stdout);
}
return 0;
}
Test application:
mitsuhiko@nausicaa:/tmp$ ./a.out
PID = 22806
Terminated
mitsuhiko@nausicaa:/tmp$ ./a.out
PID = 22809
mitsuhiko@nausicaa:/tmp$ ./a.out
PID = 22812
^Z
[2]+ Stopped ./a.out
mitsuhiko@nausicaa:/tmp$ fg
./a.out
test
test
foo
foo
First signal sent was TERM, second was INT. Last case was sending to background, receiving the ignored SIGCONT signal, fgetc returning -1 and fgetc being called again because of errno being EINTR. |
|
Date |
User |
Action |
Args |
2010-09-16 12:34:05 | aronacher | set | recipients:
+ aronacher, loewis, ronaldoussoren, ned.deily |
2010-09-16 12:34:05 | aronacher | set | messageid: <1284640445.49.0.754017666834.issue9867@psf.upfronthosting.co.za> |
2010-09-16 12:34:04 | aronacher | link | issue9867 messages |
2010-09-16 12:34:03 | aronacher | create | |
|