#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <sys/wait.h>
#include <string.h>
typedef struct poruka{
    long tip;
    int operacija;
    int rezultat;
}PorukaKorisnik;

typedef struct {
    long tip;
    int operacija;
    int rednibroj;
}PorukaRadniCvor;

enum{PRISTUP_KORISNIK, PRIJAVA_RC, ZARSENI_ZADACI_RC, MUTEXDELJENA};

union semun {
               int              val;    /* Value for SETVAL */
               struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
               unsigned short  *array;  /* Array for GETALL, SETALL */
               struct seminfo  *__buf;  /* Buffer for IPC_INFO
                                           (Linux-specific) */
}arg;
#define TIP_KORISNK 444
#define TIP_GLAVNICVOR 555
#define TIP_RADNICVOR 666
#define msgsize sizeof(PorukaKorisnik)-sizeof(long)
int main(){

    key_t key = ftok("/init.c",1);

    int msgid = msgget(key, IPC_CREAT | 0666);
    int shmid = shmget(key, 12*sizeof(int), IPC_CREAT | 0666);
    int semid = semget(key,4,IPC_CREAT | 0666);

    int *niz = (int*)shmat(shmid, NULL,0);
   



    arg.val = 1;
    semctl(semid, PRISTUP_KORISNIK, SETVAL, arg);
    //semctl(semid, ZADATAK_GC, SETVAL, arg);
    semctl(semid,MUTEXDELJENA, SETVAL, arg);

    arg.val = 3;
    semctl(semid, PRIJAVA_RC, SETVAL, arg);

    arg.val =0;
    semctl(semid, ZARSENI_ZADACI_RC, SETVAL, arg);

    shmdt(niz);
    return 0;
}