From owner-freebsd-hackers Fri Nov 30 13:54:27 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from guru.mired.org (okc-65-31-203-60.mmcable.com [65.31.203.60]) by hub.freebsd.org (Postfix) with SMTP id 8DFDF37B416 for ; Fri, 30 Nov 2001 13:54:23 -0800 (PST) Received: (qmail 49541 invoked by uid 100); 30 Nov 2001 21:54:17 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15368.9.298714.294055@guru.mired.org> Date: Fri, 30 Nov 2001 15:54:17 -0600 To: David Miller Cc: freebsd-hackers@freebsd.org Subject: Re: [OT] alarm() question In-Reply-To: References: X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG David Miller 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 > #include > #include > > 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. 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