Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"bib.h"
- int *shmp;
- int semid;
- int shmid;
- void zakoncz()
- {
- printf("\nKoniec!\n");
- if(shmdt(shmp)<0) perror("Blad odlaczania pamieci dzielonej");
- if(semctl(semid,0,IPC_RMID,0)<0) perror("Blad usuwania zbioru semaforow");
- if(shmctl(shmid,IPC_RMID,NULL)<0) perror("Blad usuwania pamieci dzielonej");
- exit(1);
- }
- int main(){
- signal(SIGINT,zakoncz);
- srand(time(NULL));
- shmid= shmget(ftok("server.c",1), sizeof(int),IPC_CREAT | IPC_EXCL | PERMS);
- if (shmid==-1){
- perror("Blad tworzenia pamieci dzielonej");
- }
- shmp = shmat(shmid,0, 0);
- if (shmp==NULL){
- perror("Blad dolaczania pamieci dzielonej");
- }
- semid = semget(ftok("server.c",1), 2, IPC_CREAT | IPC_EXCL | PERMS);
- if (semid < 0){
- perror("blad tworzenia zbioru semaforow");
- }
- odblokuj_semafor2(semid);
- int liczba=1;
- while(1){
- blokuj_semafor2(semid);
- *shmp=liczba;
- liczba++;
- odblokuj_semafor1(semid);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement