View Full Version : File mapping in unix?
Algeroth
01-12-2005, 21:35
Ciao a tutti,
volevo chiedervi se č possibile fare il file mapping in unix ed eventualmente come, ossia come attaccare un file in una shared memory.
Il tutto in linguaggio c naturalmente!
Grazie a tutti :muro:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
int main(void)
{
char file[] = "/etc/fstab";
void *fileMemory;
int fd, fileLen;
fd = open(file, O_RDONLY);
fileLen = lseek(fd, 0, SEEK_END);
fileMemory = mmap(NULL, fileLen, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
write(STDOUT_FILENO, fileMemory, fileLen);
munmap(fileMemory, fileLen);
return 0;
}
Algeroth
01-12-2005, 22:33
Grazie mille per l'impegno,
ma la shared memory non la uso per niente?
ossia le varie shmget, shmat e cosė via......
Algeroth
02-12-2005, 02:51
Risolto, grazie a tutti e soprattutto a quacker :D
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.