Date: Fri, 30 Nov 2001 15:54:17 -0600 From: Mike Meyer <mwm@mired.org> To: David Miller <dmiller@sparks.net> Cc: freebsd-hackers@freebsd.org Subject: Re: [OT] alarm() question Message-ID: <15368.9.298714.294055@guru.mired.org> In-Reply-To: <Pine.BSF.4.21.0111301452350.27497-100000@search.sparks.net> References: <Pine.BSF.4.21.0111301452350.27497-100000@search.sparks.net>
next in thread | previous in thread | raw e-mail | index | archive | help
David Miller <dmiller@sparks.net> types: > Apologies for this being more C than freebsd, but I did say OT in > the subject... > > In the most basic use of an alarm, like this: > > #include <stdio.h> > #include <unistd.h> > #include <signal.h> > > sig_t > signal(int sig, sig_t func); > > static void bzzt() { > printf("In routine bzzt now, timer expired after 3 seconds\n"); > } > > main() { > > signal(SIGALRM, bzzt); > alarm(3); > system("/usr/bin/host -t soa 111.0.12.in-addr.arpa"); > printf("Done\n"); > } > > Why does the alarm go off but not interrupt the system call? bzzt() is > executed, but the program doesn't print Done and exit for a minute plus. > > Pointers to FM to RT welcome. Try the system() man page. system() does a fork, then exec's a shell with the string. So in the child process, the ALARM handling will be done by the shell, and I'm pretty sure it ignores them. As you noticed, the parent process gets the alarm. Checking the wait system page says that wait system calls - like the one done by the system() library routine - may either be interrupted, or restarted after the signal handler runs. Guess which one is happening here. <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/ Q: How do you make the gods laugh? A: Tell them your plans. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15368.9.298714.294055>