Advertisement
Guest User

Untitled

a guest
May 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <semaphore.h>
  5. #include <unistd.h>
  6. #include <sys/stat.h>
  7. #include <sys/types.h>
  8. #include <float.h>
  9. #include <sys/mman.h>
  10. #include <sys/sem.h>
  11.  
  12.  
  13. int main()
  14. {
  15. double *rptr;
  16. //FILE *fp;
  17. sem_t *sem;
  18. int fd;
  19. int fp = open("input.asc",O_RDONLY,0777);
  20. sem = sem_open("mm", O_CREAT,0777, 0);
  21.  
  22. fd = shm_open("c", O_CREAT | O_RDWR, 0777);
  23.  
  24. if (ftruncate(fd, sizeof(double)) == -1)
  25.  
  26. printf("foram \n");
  27. rptr = (double *)mmap(NULL, sizeof(double), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  28.  
  29. printf("foram \n");
  30.  
  31. while(1){
  32.  
  33. // if (feof(fp))
  34. //{
  35.  
  36. // break;
  37. // }
  38.  
  39. sem_post(sem);
  40. read(fp,&rptr,sizeof(double));
  41. printf("frptr %lf \n", *rptr);
  42. sem_wait(sem);
  43.  
  44. }
  45.  
  46.  
  47. *rptr = DBL_MIN;
  48.  
  49. close(fp);
  50. sem_close(sem);
  51. sem_unlink("mm");
  52. shm_unlink("c");
  53. //munmap(rptr);
  54. exit(0);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement