Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/shm.h>
- #include <sys/sem.h>
- #include <valgrind/memcheck.h>
- int main() {
- const char *IPC_PATH="/home/jason/ipcfile";
- int unset;
- int *buf;
- int ret, val;
- int shm, semid;
- key_t memKey;
- /* Pull the semaphore id from the shared memory */
- memKey = ftok(IPC_PATH, 1);
- shm = shmget(memKey, sizeof(int), 0660);
- buf = shmat(shm, NULL, 0);
- semid = *buf;
- /* Pull the value from the semaphore */
- val = semctl(semid, 0, GETVAL);
- printf("Semaphore %i value is %i\n", semid, val);
- /* detach from the shared mem */
- ret = shmdt(buf);
- return 0;
- }
Add Comment
Please, Sign In to add comment