[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

mmap(2) functionality on Debian



Hi,

I'm new to the list so if this has been a topic of discussion in the
past, I apologize for redundancy.

I'm trying to use mmap on Debian linux with the MAP_ANONYMOUS |
MAP_SHARED flags.  I'm doing it BSD style and SVR4 style (using
/dev/zero as the fd for SVR4 and -1 as the fd for BSD).

In both situations, I'm getting an EINVAL (Invalid Argument) returned no
matter what I do.

I've looked all over the web for notes or problems with mmap and I don't
know what I'm missing.

Here's a simple piece of code that I'm using as a test - does anyone
know what's up with this?

Also, if mmap is broke for this situation, does anyone know of a really
good (efficient) means of communication between a parent and child
process other than this?

Thanks,

D


/*
 * Trying to mmap in integer as shared anonymous
 */

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

int main (argc, argv)
    int     argc;
    char    *argv[];
{
    int * ptr;
    int fd;

    fd = open("/dev/zero", O_RDWR);

    if ( (ptr=(int *)mmap(moveto, sizeof(int),
        PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, fd, 0L)))
        fprintf(stderr, "Error %i: %s\n", errno, strerror(errno));

    close(fd);
    exit(1);

}


Reply to: