The code below works correctly when no Optimization flag is given to gcc and process exits as soon as a SIGHUP is sent to it. But if it is compiled with any one of -O flags, sending SIGHUP does not terminate the process.
sig_atomic_t hup_rcvd = 0; void hup_handler(int signo) { hup_rcvd = 1; } int main() { if (signal(SIGHUP, hup_handler) == SIG_ERR) { fprintf(stderr, "signal failed\n"); return -1; } for (hup_rcvd = 0; !hup_rcvd; ) { ; } return 0; } -- Summary: Incorrect code with -O Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: alireza dot salimi at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29429