31 lines
577 B
C
31 lines
577 B
C
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/mman.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int fd = open(argv[1], O_RDWR | O_CREAT, (mode_t)0600);
|
|
const char *text = "hello";
|
|
size_t textsize = strlen(text) + 1;
|
|
char *map;
|
|
|
|
lseek(fd, textsize-1, SEEK_SET);
|
|
write(fd, "", 1);
|
|
|
|
map = mmap(0, textsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
printf("address is 0x%x\n", (unsigned long)map);
|
|
|
|
memcpy(map, text, strlen(text));
|
|
|
|
//while(1);
|
|
|
|
msync(map, textsize, MS_SYNC);
|
|
munmap(map, textsize);
|
|
|
|
close(fd);
|
|
return 0;
|
|
}
|
|
|