added getsemid

This commit is contained in:
Lorenzo Bianchi 2023-05-14 22:19:52 +02:00
parent cdc14ee0e7
commit dddb1d3b53
1 changed files with 22 additions and 0 deletions

View File

@ -2,8 +2,13 @@
#include <stdlib.h>
#include <ctype.h>
#include <server.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <errExit.h>
#include <structures.h>
input_server_t check_input(int argc, char *argv[]){
if (argc < 5) {
@ -34,4 +39,21 @@ input_server_t check_input(int argc, char *argv[]){
}
return input;
}
int getSemid(){
int semid = semget(IPC_PRIVATE, 4, S_IRUSR | S_IWUSR);
if (semid == -1) {
errExit("semget", "getSemid");
}
int val[] = {0, 0, 0, 0};
union semun arg;
arg.array = val;
if (semctl(semid, 0 , SETALL, arg) == -1) {
errExit("semctl", "getSemid");
}
return semid;
}