- Straight foward copy is time and space consuming
- Different processes should be able to share the read-only code (not the data) segment.
Rather than copying a program into a process's address space, a better choice is to map the program file into the address space.
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
- start - just a suggestion to the operating system. Use 0.
- length - size of the file in bytes! (see stat or fstat functions)
- prot
- PROT_EXEC Pages may be executed.
- PROT_READ Pages may be read.
- PROT_WRITE Pages may be written (and read).
- PROT_NONE Pages may not be accessed.
- flags
- MAP_SHARED
- MAP_PRIVATE