blob: 2043360d087ade3de57dddd74f0c2630b0eba173 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
const char msg[] = "hello world";
size_t msglen = strlen(msg) + 1;
int shmd = shm_open("/shm", O_RDONLY, 0755);
ftruncate(shmd, msglen);
char* memory = mmap(NULL, msglen, PROT_READ, MAP_SHARED, shmd, 0);
char buf[1024];
strncpy(buf, memory, msglen);
write(1, buf, msglen);
munmap(memory, msglen);
close(shmd);
shm_unlink("/shm");
return 0;
}
|