This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

second call to mmap() results in error


My application needs several areas of shared memory, and I am getting an
error ("No such device") on the second call to mmap(). The first call works
fine.

Here a simple program that shows the error (compiled with
gcc -o mmaptest mmaptest.c -lrt):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <sys/mman.h>

int main()
{
        int shm_fd1, shm_fd2;         
        char *mmap1, *mmap2;
 /*   get fd for each block of memory  */
  shm_fd1 = shm_open("/block1", O_CREAT | O_RDWR, 0666);
  if (shm_fd1 == -1) {
                fprintf(stderr, "Couldn't get fd for block1 (%s)\n",
strerror(errno));
                exit(1);
  }
  shm_fd2 = shm_open("/block2", O_CREAT | O_RDWR, 0666);
  if (shm_fd2 == -1) {
                fprintf(stderr, "Couldn't get fd for /UNI_queue (%s)\n",
strerror(errno));
                exit(1);
  }
  /*  map each block  */
  mmap1 = mmap(NULL, 524304, PROT_WRITE | PROT_READ, MAP_SHARED, shm_fd1,
0);
        if (mmap1 == (char *)-1) {
                fprintf(stderr, "Couldn't map memory for /block1 (%s)\n",
strerror(errno));
                exit(1);
        }
  mmap2 = mmap(NULL, 524304, PROT_WRITE | PROT_READ, MAP_SHARED, shm_fd2,
0);
        if (mmap2 == (char *)-1) {
                fprintf(stderr, "Couldn't map memory for /block2 (%s)\n",
strerror(errno));
                exit(1);
        }
        fprintf(stdout, "Shared memory initialized\n");
        exit(0);
}

The problem does not seem to depend on the size of the requested memory. The
program
always returns with "Couldn't map memory for /block2 (No such device)"

Steve Bardwell

Attachment: cygcheck.out
Description: Binary data

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]