İşletim Sistemleri (Bahar-2016) Hafta-14/2
Uygulamada önce proc1.cpp çalıştırılmalıdır. Root seviyesinde çalıştırmayı unutmayınız!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include<iostream> #include<unistd.h> #include<sys/sem.h> #include<sys/ipc.h> #include<stdlib.h> #include<cstdio> using namespace std; int main() { union semun{ int val; //struct semid_ds *buf; //unsigned short int *array; //struct seminfo *inf; }; int sem_id, cikis; struct sembuf islemler[1]; union semun ozellik; ozellik.val=0; // p durumu baslangic degeri sem_id = semget(101,1,IPC_CREAT | IPC_EXCL); cout<<"Sem ID:"<<sem_id<<endl; if(sem_id==-1) { cout<<"semget error"<<endl; perror("semget"); exit(0); } semctl(sem_id,1,SETVAL,ozellik); islemler[0].sem_num=0; islemler[0].sem_op=-1; // p islemine girildikten sonraki degiskenin degerinin degistirilmesi islemler[0].sem_flg=SEM_UNDO; cout<<"P durumu!"<<endl; cikis = semop(sem_id,islemler,1); if(cikis>-1){ cout<<"v izin gonderdi KB deyiz"<<endl; // semafor u yok etmek icin kod yazilacak semctl(sem_id,1,IPC_RMID,ozellik); } else { cout<<"hata olustu!"<<endl; perror("semop"); } } |
proc1.cpp P() işlemi yaparken (bekleme durumu) aşağıdaki kod root seviyesinde çalıştırıldığında
Okumaya devam et
Son Yorumlar