Message116538
| Author |
aronacher |
| Recipients |
aronacher, loewis, ned.deily, ronaldoussoren |
| Date |
2010年09月16日.12:34:03 |
| SpamBayes Score |
4.7262227e-05 |
| Marked as misclassified |
No |
| Message-id |
<1284640445.49.0.754017666834.issue9867@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|