Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <stdlib.h>
- #include <sys/sem.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- int shmCreate(key_t key, int sizeInBytes)
- {
- int semId = shmget(key,sizeInBytes,IPC_CREAT|IPC_EXCL|0700);
- if(semId == -1)
- {
- perror("Blad tworzenia");
- exit(1);
- }
- return semId;
- }
- int shmOpen(key_t key)
- {
- int semId=shmget(key,0,0700);
- if(semId == -1)
- {
- perror("Blad otwarcia");
- exit(1);
- }
- return semId;
- }
- void shmRemove(int shmid)
- {
- if(shmctl(shmid,IPC_RMID,NULL) == -1)
- {
- perror("Blad usuniecia");
- exit(1);
- }
- }
- void *shmAt(int shmid)
- {
- int* score=shmat(shmid,NULL,0);
- if(*score == -1)
- {
- perror("Blad at");
- exit(1);
- }
- return shmat(shmid,NULL,0);
- }
- void shmDt(void*addr)
- {
- if(shmdt(addr) == -1)
- {
- perror("Blad dt");
- exit(1);
- }
- }
- #include "pamiecwspoldzielona.h"
- int main()//-zapis
- {
- key_t key = ftok(".",0);
- int a=shmCreate(key,sizeof(long double));
- long double *bufor;
- bufor=(long double*)shmAt(a);
- *bufor=69.696969;
- shmDt(bufor);
- return 0;
- }
- #include "pamiecwspoldzielona.h"
- int main()//-odczyt
- {
- key_t key = ftok(".",0);
- int a=shmOpen(key);
- long double*b=shmAt(a);
- printf("%Lf\n",*b);
- shmDt(b);
- shmRemove(a);
- return 0;
- }
Add Comment
Please, Sign In to add comment