Beanalby

testClient.c for http://home.beanalby.net/blog/2012/valgrind

Jun 8th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/shm.h>
  3. #include <sys/sem.h>
  4. #include <valgrind/memcheck.h>
  5.  
  6. int main() {
  7.   const char *IPC_PATH="/home/jason/ipcfile";
  8.   int unset;
  9.   int *buf;
  10.   int ret, val;
  11.   int shm, semid;
  12.   key_t memKey;
  13.  
  14.   /* Pull the semaphore id from the shared memory */
  15.   memKey = ftok(IPC_PATH, 1);
  16.   shm = shmget(memKey, sizeof(int), 0660);
  17.   buf = shmat(shm, NULL, 0);
  18.   semid = *buf;
  19.  
  20.   /* Pull the value from the semaphore */
  21.   val = semctl(semid, 0, GETVAL);
  22.   printf("Semaphore %i value is %i\n", semid, val);
  23.  
  24.   /* detach from the shared mem */
  25.   ret = shmdt(buf);
  26.  
  27.   return 0;
  28. }
Add Comment
Please, Sign In to add comment