void init_platforms(){ if(signal(SIGUSR1, train_leaving_signal) == SIG_ERR){ printf("%s\n", "Error in catching SIGUSR1"); } int shmid; shmid = allocateSharedMemory(sizeof(int), SHMTOKEN); platform_pid = (int *) mapSharedMemory(shmid); int i; for (i = 0; i< PLATFORMS; i++){ int pipefd[2]; pipe(pipefd); int pid = fork(); print_error(pid, "Faield to fork"); if (pid == 0){ close(pipefd[1]); char *port_arg = (char*)malloc(sizeof(char)*20); sprintf(port_arg,"%d",platforms[i].port); char *pno = (char*)malloc(sizeof(char)*20); sprintf(pno, "%d", platforms[i].pno); dup2(pipefd[0],0); execl("platform.out", "platform.out", pno, port_arg, (char*)0); } else{ close(pipefd[0]); platforms[i].pid = pid; platforms[i].pfd = pipefd[1]; } } }
int main () { segment_id = allocateSharedMemory(0); semaphore_id = semaphoreAllocation(); /* printf("KonsumentA#main: Shared Memory id: %d\n", segment_id); printf("KonsumentA#main: Semafor id: %d\n", semaphore_id);*/ for (int i = 0; i < 10; ++i) { getElementInfA("A"); usleep(10000); } printf("KONIEC KonsumentA\n"); return 0; }
int main(){ signal(SIGUSR1, _signal); int token = 123413; int shmid; shmid = allocateSharedMemory(sizeof(int), token); printf("shmid is %d\n", shmid); PID = (int *) mapSharedMemory(shmid); *(PID) = 0; _p2(); _p6(); while(1){ sleep(7); printf("[p1->hey]\n"); fflush(stdout); // sleep(10); } }
int main(){ token = ftok(".",'r'); shmid = allocateSharedMemory(sizeof(struct sems), token); s = (struct sems *) mapSharedMemory(shmid); s->x = 0; s->y = 1; if(signal(SIGINT, clean) == SIG_ERR){ printf("%s\n", "Error in catching SIGINT"); } printf("P1.this is x %d \n",s->x); printf("P1.this is y %d \n",s->y); sem_init(&s->s1, 0, token+1); sem_init(&s->s2, 0, token+2); // printf("P1.this is s1 %d \n",s->s1); // printf("P1.this is s2 %d \n",s->s2); while(1){ printf("P1 just wrote X as %d\n", s->x); sem_up(&s->s1); sem_down(&s->s2); int y = s->y; s->x = y+1; } raise(SIGINT); // printf("unlocked\n"); // sem_up(&s->s1); // printf("first\n"); // sem_down(&s->s1); // printf("second\n"); // sem_down(&s->s1); // printf("fourth\n"); }