Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/mman.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <stdlib.h>
- #include <time.h>
- #include <semaphore.h>
- #define shm_path "shm123"
- #define sem_path "sem123"
- #define MAX_MSG_LENGTH 50
- struct msg_s {
- int type;
- int content;
- };
- int main(int argc, char *argv[]) {
- int deskryptor;
- int rozmiar = (1 * sizeof(struct msg_s));
- struct msg_s *shared_msg;
- sem_t * sem = sem_open(sem_path, 0);
- sem_wait(sem);
- deskryptor = shm_open(shm_path, O_RDWR, S_IRWXU | S_IRWXG);
- printf("Otwarto pamiec wspoldzielona %s\n", shm_path);
- shared_msg = (struct msg_s *)mmap(NULL, rozmiar, PROT_READ | PROT_WRITE, MAP_SHARED, deskryptor, 0);
- printf("Odczytany pid w SHM: %d\n", shared_msg->content);
- shared_msg->content=getpid();
- printf("Ustawianie pid w SHM na: %d\n", shared_msg->content);
- munmap(0, rozmiar);
- sem_post(sem);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement