#include #include #include #include #include #include #include int main(int argc, char *argv[]) { char *addr; char *mfile = "lena.jpg"; char infile[64]; int fd01, fd02; pid_t pid; struct stat st; fd01 = open(mfile, O_RDWR); stat(mfile, &st); addr = (char*)mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd01, 0); pid = fork(); if(pid == 0) { execlp("display", "display","-update","2", mfile, 0 ); //execlp("display", "display", "-update", "2", "MAP.jpg", NULL); } else { while(1) { gets(infile); fd02 = open(mfile, O_RDONLY); stat(fd02, &st); ftruncate(fd02, st.st_size); addr = (char*)mmap(addr, st.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd02, 0); read(fd02, addr, st.st_size); msync(addr, st.st_size, 0); close(fd02); } } munmap(addr, st.st_size); close(fd01); return 0; }