Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Feb 1998 10:14:57 +0200 (SAT)
From:      Graham Wheeler <gram@cdsec.com>
To:        hackers@FreeBSD.ORG
Subject:   Re: Shared memory and signals 
Message-ID:  <199802060814.KAA01502@cdsec.com>

next in thread | raw e-mail | index | archive | help
> 
> > > 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/






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199802060814.KAA01502>