Advertisement
Guest User

Untitled

a guest
May 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/ipc.h>
  6. #include <sys/shm.h>
  7. #include <errno.h>
  8. #include <string.h>
  9.  
  10. #define SHMSZ 27
  11.  
  12. int main(int argc, char * argv[]) {
  13.     int shmid;
  14.     key_t key;
  15.     int *shm, *data;
  16.     int c;
  17.  
  18.     /*We need to get the segment named "666", created by the server*/
  19.     key = 666;
  20.  
  21.     /*Locate the segment*/
  22.     if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {
  23.         perror(strerror(errno));
  24.         exit(1);
  25.     }
  26.  
  27.     if ((shm = shmat(shmid, NULL, 0)) == (int *) -1) {
  28.             perror(strerror(errno));
  29.             exit(1);
  30.     }
  31.  
  32.     /*Read what the server put in the memory*/
  33.     data = shm;
  34.     for (c = 0; c < 3; c++) {
  35.         printf("test\n");
  36.             printf("%i\n", *data++);
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement