From owner-freebsd-hackers Tue Aug 14 15:25:50 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mx01-a.netapp.com (mx01-a.netapp.com [198.95.226.53]) by hub.freebsd.org (Postfix) with ESMTP id AFAB537B40C for ; Tue, 14 Aug 2001 15:25:37 -0700 (PDT) (envelope-from boshea@netapp.com) Received: from frejya.corp.netapp.com (frejya.corp.netapp.com [10.10.20.91]) by mx01-a.netapp.com (8.11.1/8.11.1/NTAP-1.2) with ESMTP id f7EMPaX09524; Tue, 14 Aug 2001 15:25:37 -0700 (PDT) Received: from eclipse-fe.eng.netapp.com (localhost [127.0.0.1]) by frejya.corp.netapp.com (8.11.1/8.11.1/NTAP-1.2) with ESMTP id f7EMPac19670; Tue, 14 Aug 2001 15:25:36 -0700 (PDT) Received: (from boshea@localhost) by eclipse-fe.eng.netapp.com (8.8.8+Sun/8.8.8) id PAA28752; Tue, 14 Aug 2001 15:25:36 -0700 (PDT) Date: Tue, 14 Aug 2001 15:25:36 -0700 From: "brian o'shea" To: Hans Zaunere Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Signal Handling Message-ID: <20010814152536.B27553@netapp.com> References: <20010813160932.30924.qmail@web12801.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/0.96.3i In-Reply-To: <20010813160932.30924.qmail@web12801.mail.yahoo.com>; from Hans Zaunere on Mon, Aug 13, 2001 at 09:09:32AM -0700 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 On Mon, Aug 13, 2001 at 09:09:32AM -0700, Hans Zaunere wrote: [...] > However in reading about this, in Steven's Advanced > Programming in the UNIX Environment, he states: > "Naturally a signal that is being caught by a process > that calls exec cannot be caught in the new program, > since the address of the signal-catching function in > the caller probably has no meaning in the new program > file that is execed. Page. 273) > > This makes sense to me, however doesn't seem to be the > case. Three questions: This is true, except in the case where you exec() the same executable that called exec() in the first place. It sounds like this is what you are doing (calling exec() with argv[0] as the path to the new executable). In that case, the signal handler's address will be the same. Unix unsets the signal handler in the exec()ed process to handle the common case, which is that most people use exec() after a fork() to run a new executable. It is highly unlikely that the signal handlers for a given signal in two different executable files will have the same address. > 1) Why, in the first place, does a signal become > blocked after it is recieved? Why does the kernel > want to do this? I think it's to prevent the signal handler from being called while your process is alredy executing the handler. If your process receives signal 15, it is stopped by the kernel and the handler for that function is called. If while the handler is executing, the process receives signal 15 again, you don't want the signal handler to be called while it is already executing. Anybody else have some input on this? > 2) If a 10k binary is running, the signal is sent, and > the program is reloaded from disk, but is 100k (or 1k > even) how does the signal handling function get > called, taking into account what Stevens says. Steven > states that the sigmask remains for calls across exec, > so wouldn't the wrong address to the handler function > be used? No, the signal mask is not the address of the handler function. It is the bit mask which determines which signals are blocked. > 3) Is my using of exec, in fact, the best way to > reload the program on the fly, from within itself? > What would be the best, robust, way to do this in the > future? I think that exec() is the best way. -brian -- Brian O'Shea "Stare not too deeply into the pen, 3.3.163(PEN) lest the pen stare back into you." (408) 822-3249 -------------------------------------------------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message