Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <sys/mman.h>
  2. #include <fcntl.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <errno.h>
  7.  
  8. #include "shm.h"
  9.  
  10. int main() {
  11. int fd;
  12. sharedMemory *shm;
  13.  
  14.  
  15. if ( (fd = shm_open("/ourMagnificiantShm", O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1) {
  16. perror("shm_open");
  17. }
  18. if (ftruncate(fd, sizeof(sharedMemory)) == -1) {
  19. perror("ftruncate");
  20. }
  21. shm = (sharedMemory*) mmap(NULL, sizeof(sharedMemory), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  22.  
  23. if (shm == MAP_FAILED) {
  24. perror("mmap");
  25. }
  26. printf("Adr memoire partagée: %x \n", shm);
  27.  
  28. shm_unlink("/ourMagnificiantShm");
  29.  
  30. return 1;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement