Ask a Question related to UNIX Programming, Design and Development.
-
Michael B Allen #1
Automatically Unlink POSIX Shared Mem?
I only want a shared memory segment to exist if 1 or more processes
are attached to it. I suppose I could store a link count in the shared
memory itself and have the last process to detach call shm_unlink but
I was hoping there was an elegant solution builtin.
Actually, what I'd _really_ like to do is have the shared memory
segment automatically unlink itself if no processes are attached after
a configurable amount of time like 5 minutes.
Is this possible?
Thanks,
Mike
Michael B Allen Guest
-
Unlink and variables
Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a... -
Still need unlink help!! God help me. - Revisited
<20030808202717051099.GyazMail.neuroball@usa.net> <YW50aWdvbmU=.45ab06a65368617cf57750f9f6311818@1060402929.cotse.net> -
Still need unlink help!! God help me.
Still having problem with unlink. My original problem began with deleting files from a list. I seem to have fixed the problem reading the list but... -
Help with Unlink please
> Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400: Neither of these worked. I am beginning to think that there is something wrong with... -
problem using unlink()
Hi, I have a problem using unlink(); on a system using FreeBSD and Apache... where my local system using Windows and Apache experiences no... -
Gianni Mariani #2
Re: Automatically Unlink POSIX Shared Mem?
Michael B Allen wrote:
No. The kernel provides no such function.> I only want a shared memory segment to exist if 1 or more processes
> are attached to it. I suppose I could store a link count in the shared
> memory itself and have the last process to detach call shm_unlink but
> I was hoping there was an elegant solution builtin.
>
> Actually, what I'd _really_ like to do is have the shared memory
> segment automatically unlink itself if no processes are attached after
> a configurable amount of time like 5 minutes.
>
> Is this possible?
Somthing comes close. If you create a file, map it to N processes and
then unlink the file, the file will remain available to all the
processes that have it mapped. The file is deleted when it is no longer
mapped. However, once the file is unlinked from the file system, it no
longer can be mapped by an independant process.
Gianni Mariani Guest
-
James Antill #3
Re: Automatically Unlink POSIX Shared Mem?
On Sun, 06 Jul 2003 00:34:53 -0400, Michael B Allen wrote:
Why don't you just used mmap() and MAP_SHARED? This is a much cleaner> I only want a shared memory segment to exist if 1 or more processes
> are attached to it. I suppose I could store a link count in the shared
> memory itself and have the last process to detach call shm_unlink but
> I was hoping there was an elegant solution builtin.
interface, however even then you can't say delete this in X seconds if
noone is using it.
There is a trick used in gimp/xscreensaver (and porbably elsewhere) that
lets you portably say "destroy this SHM segment if all attached processes
die".
--
James Antill -- [email]james@and.org[/email]
Need an efficent and powerful string library for C?
[url]http://www.and.org/vstr/[/url]
James Antill Guest
-
Rich Gray #4
Re: Automatically Unlink POSIX Shared Mem?
Gianni Mariani wrote:
But, I suppose an independant process could obtain a file handle to the>
> Michael B Allen wrote:>> > I only want a shared memory segment to exist if 1 or more processes
> > are attached to it. I suppose I could store a link count in the shared
> > memory itself and have the last process to detach call shm_unlink but
> > I was hoping there was an elegant solution builtin.
> >
> > Actually, what I'd _really_ like to do is have the shared memory
> > segment automatically unlink itself if no processes are attached after
> > a configurable amount of time like 5 minutes.
> >
> > Is this possible?
> No. The kernel provides no such function.
>
> Somthing comes close. If you create a file, map it to N processes and
> then unlink the file, the file will remain available to all the
> processes that have it mapped. The file is deleted when it is no longer
> mapped. However, once the file is unlinked from the file system, it no
> longer can be mapped by an independant process.
unlinked file by using some form of IPC to request a holder of the
file's
fd pass a descriptor using sendmsg() over a Unix domain socket (UNPv1
section 14.7) or via a door (UNPv2 section 15.8). I've never tried
either technique.
Rich
--
mailto:richNOgSPAM@plustechnologies.com (remove NO SPAM to reply)
[url]http://www.plustechnologies.com[/url]
Rich Gray Guest
-
Martijn Sipkema #5
Re: Automatically Unlink POSIX Shared Mem?
[...]
message queue descriptors are not file descriptors though, so that won't> But, I suppose an independant process could obtain a file handle to the
> unlinked file by using some form of IPC to request a holder of the
> file's
> fd pass a descriptor using sendmsg() over a Unix domain socket (UNPv1
> section 14.7) or via a door (UNPv2 section 15.8). I've never tried
> either technique.
work.
--ms
Martijn Sipkema Guest
-
Martijn Sipkema #6
Re: Automatically Unlink POSIX Shared Mem?
[...]
Oh, I'm sorry, I somehow thought message queues were ment. Yes, for POSIX> True, but this thread has been about shared memory, which can be created
> with the mmap function which takes a file descriptor. The file
> descriptor
> could be passed to another process (even unrelated) and mapped there,
> even
> if the file has been unlinked.
>>> > so that won't work.
> >
> > --ms
> It _should_ work, but I've never tried it.
shared memory this will work.
--ms
Martijn Sipkema Guest



Reply With Quote

