Last active
September 30, 2021 00:26
-
-
Save dulimarta/b753628fa5b468a9c2bd to your computer and use it in GitHub Desktop.
CS452 Lab05 - Sample 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <sys/ipc.h> | |
#include <sys/shm.h> | |
#define FOO 4096 | |
int main () { | |
int shmId; | |
char *shmPtr; | |
if ((shmId = | |
shmget (IPC_PRIVATE, FOO, | |
IPC_CREAT | S_IRUSR | S_IWUSR)) < 0) { | |
perror ("i can't get no..\n"); | |
exit (1); | |
} | |
if ((shmPtr = shmat (shmId, NULL, 0)) == (void *) -1) { | |
perror ("can't attach\n"); | |
exit (1); | |
} | |
printf ("value a: %lu\t value b: %lu\n", (unsigned long) shmPtr, | |
(unsigned long) shmPtr + FOO); | |
if (shmdt (shmPtr) < 0) { | |
perror ("just can't let go\n"); | |
exit (1); | |
} | |
if (shmctl (shmId, IPC_RMID, 0) < 0) { | |
perror ("can't deallocate\n"); | |
exit (1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment