Advertisement
d1cor

map_seq.c

Aug 16th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. /*******************************************
  2. * Author     : Diego Cordoba / @d1cor      *
  3. * Purpose    : juncotic.com  / um.edu.ar   *
  4. *******************************************/
  5.  
  6. #include<stdio.h>
  7. #include<stdio.h>
  8. #include<stdlib.h>
  9. #include<sys/types.h>
  10. #include<sys/stat.h>
  11. #include<unistd.h>
  12. #include<dirent.h>
  13. #include<fcntl.h>
  14. #include<errno.h>
  15. #include<sys/mman.h>
  16. #include<string.h>
  17.  
  18. #define MIN_SIZE 128
  19.  
  20. int main(int argc, char** argv) {
  21.  
  22.     int fd,i=0;
  23.     char *buffer;
  24.     struct stat estado;
  25.     fd=open("/tmp/archivo.txt",O_RDWR|O_CREAT,0777);
  26.     printf("%s\n",strerror(errno));
  27.  
  28.  
  29.  
  30.     fstat(fd,&estado);
  31.  
  32.     if(estado.st_size < MIN_SIZE){
  33.         ftruncate(fd,MIN_SIZE);
  34.     }
  35.  
  36.     printf("Tamanio: %d\n",estado.st_size);
  37.  
  38.     if((buffer=mmap(NULL, MIN_SIZE, PROT_WRITE, MAP_SHARED, fd, 0))<0){
  39.         close(fd);
  40.         perror("Error de mapeo");
  41.         printf("%s\n",strerror(errno));
  42.         exit(EXIT_FAILURE);
  43.     }
  44.  
  45.  
  46.     for(i=0;i<15;i++){
  47.         *(buffer+i)=*argv[1];
  48.         msync(buffer,estado.st_size,MS_ASYNC);
  49.         printf("%s\n",strerror(errno));
  50.         sleep(1);
  51.     }
  52.  
  53.     munmap(buffer,MIN_SIZE);
  54.  
  55.     return 0;
  56. }
  57.  
  58. ssh ro-SVhn36GZw9r1fYCJjimo1Yy5O@ny2.tmate.io
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement