wklejamy.pl website for sale. You are interested in. Please contact. wklejamy@gmail.com
Click to buy coffe
Untitled
Guest 90 18th May, 2023
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdlib.h>
static struct sembuf buf;
void podnies(int semid, int semnum){
buf.sem_num = semnum;
buf.sem_op = 1;
buf.sem_flg = 0;
if (semop(semid, &buf, 1) == -1){
perror("Podnoszenie semafora\n");
exit(1);
}
printf("Poniesiono semafor\n");
}
void opusc(int semid, int semnum){
buf.sem_num = semnum;
buf.sem_op = -1;
buf.sem_flg = 0;
if (semop(semid, &buf, 1) == -1){
perror("Opuszczenie semafora\n");
exit(1);
}
printf("Opuszczono semafor\n");
}
int main(){
int semid=semget(45123,2,IPC_CREAT|IPC_EXCL|0660);
if(semid == -1){
printf("Blad tworzenie semafora\n");
exit(0);
}else{
printf("Utworzono semafor o id %d\n",semid);
int semok = semctl(semid, 0, SETVAL ,1);
if(semok==-1){
printf("Blad ustawienie semafora\n");
return -1;
}
opusc(semid, 0);
sleep(1);
podnies(semid, 0);
semctl(semid,0,IPC_RMID,0);
}
To share this paste please copy this url and send to your friends
RAW Paste Data