From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 19 14:03:55 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81E271065672; Fri, 19 Jun 2009 14:03:55 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 3BF6D8FC0A; Fri, 19 Jun 2009 14:03:55 +0000 (UTC) (envelope-from jilles@stack.nl) Received: by mx1.stack.nl (Postfix, from userid 65534) id 5A2B6359931; Fri, 19 Jun 2009 16:03:54 +0200 (CEST) X-Spam-DCC: dcc1: scanner01.stack.nl 1182; Body=1 Fuz1=1 Fuz2=1 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on scanner01.stack.nl X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,NO_RELAYS autolearn=ham version=3.2.5 X-Spam-Relay-Country: _RELAYCOUNTRY_ Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 592BB35992A; Fri, 19 Jun 2009 16:03:52 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 19E27228CB; Fri, 19 Jun 2009 16:03:27 +0200 (CEST) Date: Fri, 19 Jun 2009 16:03:27 +0200 From: Jilles Tjoelker To: Daniel Eischen Message-ID: <20090619140326.GA75222@stack.nl> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Cc: freebsd-hackers@freebsd.org, vasanth raonaik Subject: Re: Regarding Signal IPC X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jun 2009 14:03:55 -0000 On Fri, Jun 19, 2009 at 09:03:28AM -0400, Daniel Eischen wrote: > On Fri, 19 Jun 2009, vasanth raonaik wrote: > > I want to print out the process ID of the process which is sending the > > Signal. > > Is it possible. if yes, can you please point me to any related documents. > Though I have not tried this, there is an si_pid field > (and other fields you might be interested in) in > struct siginfo. If you use a POSIX signal handler > (see sigaction(2)), a pointer to a struct siginfo is > the 2nd argument to your signal handler. > See for the definition of struct siginfo. Meaningful siginfo is only given for signals sent by sigqueue(2), traps, child processes (SIGCHLD) and sigevent structures (for example mq_notify(2)). If you want to handle signals synchronously, you can use sigtimedwait(2). It is still necessary to call sigaction(2) with the SA_SIGINFO flag, even though the signal handler will not be called because the signal is blocked (a necessary step before using sigwait-like calls). This alternate mechanism may be particularly useful here because getting the siginfo data out of the signal handler safely is a tricky business. Although I haven't tried this, kqueue's SIGEV_SIGNAL may be helpful in managing this from a single-threaded program. This is, however, not portable. -- Jilles Tjoelker