From owner-freebsd-hackers Thu Feb 5 16:17:06 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA03572 for hackers-outgoing; Thu, 5 Feb 1998 16:17:06 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from smtp04.primenet.com (smtp04.primenet.com [206.165.6.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA03547 for ; Thu, 5 Feb 1998 16:16:56 -0800 (PST) (envelope-from tlambert@usr09.primenet.com) Received: (from daemon@localhost) by smtp04.primenet.com (8.8.8/8.8.8) id RAA29451; Thu, 5 Feb 1998 17:13:43 -0700 (MST) Received: from usr09.primenet.com(206.165.6.209) via SMTP by smtp04.primenet.com, id smtpd029408; Thu Feb 5 17:13:35 1998 Received: (from tlambert@localhost) by usr09.primenet.com (8.8.5/8.8.5) id RAA28310; Thu, 5 Feb 1998 17:13:32 -0700 (MST) From: Terry Lambert Message-Id: <199802060013.RAA28310@usr09.primenet.com> Subject: Re: Shared memory and signals To: mike@smith.net.au (Mike Smith) Date: Fri, 6 Feb 1998 00:13:32 +0000 (GMT) Cc: gram@cdsec.com, freebsd-hackers@FreeBSD.ORG In-Reply-To: <199802051118.VAA00292@word.smith.net.au> from "Mike Smith" at Feb 5, 98 09:48:42 pm X-Mailer: ELM [version 2.4 PL25] 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. > > Can you do this more cleanly by calling wait4? Unless you are sleeping > on something inside the segment, I can't *think* of any reentrancy/ > locking issues, but I would be worried about the locking you'd have to > apply around the other datastructures that your handler might be accessing. 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. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.