29 lines
746 B
C
29 lines
746 B
C
/*************************************************************************
|
|
> File Name : ipc_share_mem_posix_read.c
|
|
> Author : TL Song
|
|
> EMail : songtianlun@frytea.com
|
|
> Created Time : Wed 30 Dec 2020 03:22:20 PM CST
|
|
************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
|
|
int main(int argc, char ** argv)
|
|
{
|
|
int fd = shm_open("posixsm", O_RDONLY, 0666);
|
|
ftruncate(fd, 0x400000);
|
|
|
|
char *p = mmap(NULL, 0x400000, PROT_READ, MAP_SHARED, fd, 0);
|
|
int i = 0;
|
|
for(i = 0 ;i < 100; i++)
|
|
{
|
|
printf("Read '%c' in mem '%p'\n", *p, p);
|
|
sleep(1);
|
|
}
|
|
munmap(p, 0x400000);
|
|
return 0;
|
|
}
|