Automatically Unlink POSIX Shared Mem?

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. Still need unlink help!! God help me. - Revisited
      <20030808202717051099.GyazMail.neuroball@usa.net> <YW50aWdvbmU=.45ab06a65368617cf57750f9f6311818@1060402929.cotse.net>
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default Re: Automatically Unlink POSIX Shared Mem?

    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.

    Gianni Mariani Guest

  4. #3

    Default Re: Automatically Unlink POSIX Shared Mem?

    On Sun, 06 Jul 2003 00:34:53 -0400, 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.
    Why don't you just used mmap() and MAP_SHARED? This is a much cleaner
    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

  5. #4

    Default Re: Automatically Unlink POSIX Shared Mem?

    Gianni Mariani wrote:
    >
    > 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.
    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.

    Rich
    --
    mailto:richNOgSPAM@plustechnologies.com (remove NO SPAM to reply)
    [url]http://www.plustechnologies.com[/url]
    Rich Gray Guest

  6. #5

    Default Re: Automatically Unlink POSIX Shared Mem?

    [...]
    > 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.
    message queue descriptors are not file descriptors though, so that won't
    work.

    --ms



    Martijn Sipkema Guest

  7. #6

    Default Re: Automatically Unlink POSIX Shared Mem?

    [...]
    > 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.
    Oh, I'm sorry, I somehow thought message queues were ment. Yes, for POSIX
    shared memory this will work.

    --ms



    Martijn Sipkema Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139