Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <errno.h>
- #include "shm.h"
- int main() {
- int fd;
- sharedMemory *shm;
- if ( (fd = shm_open("/ourMagnificiantShm", O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1) {
- perror("shm_open");
- }
- if (ftruncate(fd, sizeof(sharedMemory)) == -1) {
- perror("ftruncate");
- }
- shm = (sharedMemory*) mmap(NULL, sizeof(sharedMemory), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (shm == MAP_FAILED) {
- perror("mmap");
- }
- printf("Adr memoire partagée: %x \n", shm);
- shm_unlink("/ourMagnificiantShm");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement