Professional Web Applications Themes

shared memory problem - Mac Programming

Hello all! I am having a wired probem with POSIX shared memory on MacOS X (10.3). Even the simplest calls to shared memory functions fail. Here is the source code: #include <stdio.h> #include <sys/mman.h> #include <sys/fcntl.h> int main(void) { int err; int fd = shm_open("/tmp/lock2", O_CREAT | O_RDWR, 0600); if (fd == -1) perror("shm_open"); err = shm_unlink("/tmp/lock2"); if (err == -1) perror("shm_unlink"); return 0; } The output of the compilation and program run: % gcc -c -Wall create.c % gcc -o create create.o % ./create shm_unlink: Invalid argument % As expected, the call to shm_open succeeds. Unfortunately, shm_unlink failed! I ...

  1. #1

    Default shared memory problem

    Hello all!


    I am having a wired probem with POSIX shared memory on MacOS X (10.3).
    Even the simplest calls to shared memory functions fail. Here is the
    source code:

    #include <stdio.h>
    #include <sys/mman.h>
    #include <sys/fcntl.h>

    int main(void)
    {
    int err;

    int fd = shm_open("/tmp/lock2", O_CREAT | O_RDWR, 0600);
    if (fd == -1)
    perror("shm_open");

    err = shm_unlink("/tmp/lock2");
    if (err == -1)
    perror("shm_unlink");

    return 0;
    }

    The output of the compilation and program run:
    % gcc -c -Wall create.c
    % gcc -o create create.o
    % ./create
    shm_unlink: Invalid argument
    %

    As expected, the call to shm_open succeeds. Unfortunately, shm_unlink
    failed! I cannot imagine what is going wrong here. The same code works
    on FreeBSD without complaint. Had anybody of you similar problems? Is
    there a good doentation about shared memory and MacOS X? Any hits?


    Thanks for help,
    Bernhard
    Bernhard Guest

  2. #2

    Default Re: shared memory problem

    In article
    <edvz.uni-linz.ac.at>,
    Bernhard Aichinger <jku.at> wrote:
     

    Have you looked at:
    <http://developer.apple.com/samplecode/Sample_Code/Processes/SharedMemory
    ..htm>
    Sean Guest

  3. #3

    Default Re: shared memory problem

    In article <aei.ca>,
    Sean McBride <org> wrote:
     
    >
    > Have you looked at:
    > <http://developer.apple.com/samplecode/Sample_Code/Processes/SharedMemory
    > .htm>[/ref]

    Thanks for the pointer! If I don't get it running I may switch to SysV
    functionality. Unfortunately I already have a bunch of files which use
    POSIX functions. Up to now shared memory (shm_open/shm_unlink), mapping
    (mmap) and locking (fcntl) is running smooth on FreeBSD.


    Thanks for the hint,
    Bernhard
    Bernhard Guest

  4. #4

    Default Re: shared memory problem

    In article
    <edvz.uni-linz.ac.at>,
    Bernhard Aichinger <jku.at> wrote:
     

    Oh yeah, that's right, that sample was using the SysV APIs. Hmmm, If I
    remember right, I started using those and switched to the Posix APIs.
    There have been discussions on the Darwin list, and I believe the
    conclusion was that the Posix APIs are you best bet. You can check the
    Darwin archives.
    Sean Guest

Similar Threads

  1. Shared Memory/Shared Buffers
    By Alex Turner in forum PostgreSQL / PGSQL
    Replies: 1
    Last Post: January 28th, 04:09 PM
  2. Shared memory in OS X?
    By Mike H. in forum Mac Programming
    Replies: 3
    Last Post: September 30th, 03:46 AM
  3. Problem/Question Posix Shared Memory
    By Richard in forum UNIX Programming
    Replies: 2
    Last Post: September 3rd, 11:41 AM
  4. I think I need a DB with no shared memory
    By dimonex in forum Informix
    Replies: 1
    Last Post: July 3rd, 05:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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