#include #include #include #include #include int main( void ) { union semun //...tę strukturę musimy zdefiniować we własnym zakresie { int count; struct semid_ds *stats; unsigned short int *array;struct seminfo *infos; } control; //...struktury wykorzystywane przez semop() struct sembuf P0={ 0,-1,0 },V0={ 0,1,0 },Z0={ 0,0,0 }; struct sembuf P1={ 1,-1,0 },V1={ 1,1,0 },Z1={ 1,0,0 }; //...i cała reszta key_t key; pid_t pid; int semid,flag,nsems,step; key=ftok( "/tmp", 'k'+'m' );flag=IPC_CREAT | S_IRUSR | S_IWUSR; nsems = 2; semid = semget( key,nsems,flag ); control.count = 1; semctl(semid,0,SETVAL,control); control.count = 5; semctl(semid,1,SETVAL,control); //czyli będzie 5 cykli pid = fork(); //...uaktywniamy proces potomny for( step=0;step