From owner-freebsd-hackers Fri Feb 6 00:24:42 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA26186 for hackers-outgoing; Fri, 6 Feb 1998 00:24:42 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from citadel.cdsec.com (citadel.cdsec.com [192.96.22.18]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id AAA26162 for ; Fri, 6 Feb 1998 00:24:28 -0800 (PST) (envelope-from gram@cdsec.com) Received: (from nobody@localhost) by citadel.cdsec.com (8.8.5/8.6.9) id KAA28229 for ; Fri, 6 Feb 1998 10:16:10 +0200 (SAT) Received: by citadel via recvmail id 28191; Fri Feb 6 10:15:47 1998 From: Graham Wheeler Message-Id: <199802060814.KAA01502@cdsec.com> Subject: Re: Shared memory and signals To: hackers@FreeBSD.ORG Date: Fri, 6 Feb 1998 10:14:57 +0200 (SAT) X-Mailer: ELM [version 2.4 PL25-h4.1] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG X-To-Unsubscribe: mail to majordomo@FreeBSD.org "unsubscribe hackers" > > > > I was wondering whether it is safe to call shmdt and shmctl from within > > > a signal handler. I have a program which forks off child processes which > > > communicate their results back using a shared memory segment. I would like > > > the parent to detach and release the shared memory from within the SIGCHLD > > > signal handler, but I'm not sure whether this is safe. I ended up changing this to use a pipe instead; it solved the problem and also avoids any messiness with shared memory segments getting lost if the program dies with a SIGBUS, SIGSEGV, etc. > If you use an mmap'ed file instead of a SysV SHM segment, then you > will get resource-tracking cleanup after the last close, like you > wanted. The file will stick around, but you can unlink it and use > UNIX domain sockets to pass the descriptor between processes, if this > is a problem. The overhead may be too much here (I'm speculating). The child processes get fired off rapidly and frequently (all they do is a gethostbyaddr() call and write the results back to the parent; the parent implements an async concurrent DNS cache). Ideally I should be using threads, but I wasn't sure whether gethostbyaddr is thread safe, and what other implications this would have for what is otherwise a large and complex program, of which the DNS cache is a very small component. -- Dr Graham Wheeler E-mail: gram@cdsec.com Citadel Data Security Phone: +27(21)23-6065/6/7 Internet/Intranet Network Specialists Mobile: +27(83)-253-9864 Firewalls/Virtual Private Networks Fax: +27(21)24-3656 Data Security Products WWW: http://www.cdsec.com/