second call to mmap() results in error
Steven Bardwell
SBardwell@lbmsys.com
Wed Jan 29 14:01:00 GMT 2014
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 281548 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140129/ed9bb51e/attachment.obj>
-------------- next part --------------
--
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
More information about the Cygwin
mailing list