/* iduFitManager 초기화 함수 */ IDE_RC iduFitManager::initialize() { /* FIT_ENABLE = 1 이면 loading 하고, 0 이면 하지 않는다. */ IDE_TEST( iduFitManager::getFitEnable() == IDU_FIT_FALSE ); /* iduFitManager 초기화 상태를 확인 */ if ( mIsInitialized == ID_TRUE ) { IDE_TEST( iduFitManager::finalize() != IDE_SUCCESS ); } else { /* DO NOTHING */ } /* 서버 식별자 파싱하기 */ IDE_TEST_RAISE( iduFitManager::parseSID() != IDE_SUCCESS, ERR_FIT_INITIALIZATION ); /* 메모리 할당 */ IDE_TEST_RAISE( initSleepList(&iduFitManager::mSleepList) != IDE_SUCCESS, ERR_FIT_INITIALIZATION ); /* 동적 라이브러리 fitPlugin 로딩 */ IDE_TEST_RAISE( loadFitPlugin() != IDE_SUCCESS, ERR_FIT_INITIALIZATION ); /* Shared Memory 는 성능을 위한 목적이므로 Failure 가 발생하더라도 무시한다 */ (void)attachSharedMemory(); /* fitPluging 로딩 상태 값을 변경 */ mIsPluginLoaded = ID_TRUE; /* iduFitManager 상태 값을 변경 */ mIsInitialized = ID_TRUE; return IDE_SUCCESS; IDE_EXCEPTION( ERR_FIT_INITIALIZATION ) { /* 실패 하더라도 log 만 남기고 계속 진행한다. */ IDU_FIT_LOG( "FIT Initialization Failure." ); mInitFailureCount++; /* Failure 이 IDU_FIT_INIT_RETRY_MAX 이상으로 반복될 경우FIT_ENABLE 을 0 으로 변경한다. */ if ( mInitFailureCount > IDU_FIT_INIT_RETRY_MAX ) { mIsFitEnabled = IDU_FIT_FALSE; IDU_FIT_LOG( "Set value of FIT_ENABLE to 0" ); } else { /* Do nothing */ } } IDE_EXCEPTION_END; return IDE_SUCCESS; }
int main() { int key1=ftok(".",1); int key2=ftok(".",2); int key3=ftok(".",3); printf("%d %d %d",key1,key2,key3); int semid =createSemaphore(key1,2);//S1 S2 int shmid1=createSharedMemory(key2,10);//x printf("shmid1 %d from main\n",shmid1); char *X =(char *)attachSharedMemory(shmid1); // int shmid2=createSharedMemory(key3,10);//y // printf("shmid2 %d from main\n",shmid2); char *Y ; //=//(char *)attachSharedMemory(shmid2); int *values=(int *)malloc(sizeof(int *)*2); *values=0;*(values+1)=0; initSemaphore(semid,values); /* V(semid,0); printf("hi"); P(semid,0); */ int x=0,y=0,i; while(1) { // write(x) i=0; printf("P1 X=%d Y=%d\n",x,y); while(x>0) { *X=x%10-'0';x/=10;X++;i++; } printf("*\n"); *X='\0'; printf("*\n"); X-=i;//X Points to start of shared memory //V(1) V(semid,0); //P(2) P(semid,1); //Read Y i=0; while(*Y!='\0') { y=y*10+(*Y+'0');Y++;i++; } Y-=i; //X=Y+1; x=y+1; printf("P1 X=%d Y=%d\n",x,y); } }
//======================================================================== // WingmanClient::WingmanClient() //======================================================================== WingmanClient::WingmanClient (int devNum, char *serverName) : Client(serverName) { d_jsData = NULL; d_deviceNumber = devNum; if(d_status.isStatusError()) return; if(attachSharedMemory() != 0) d_status.setStatusError(); d_status.setStatusOk(); }
int main() { printf("PID %d (pellet) started\n", getpid()); // Setup signal intercepts from swim_mill signal(SIGINT, catchKillSig); signal(SIGUSR1, catchEndSig); // Attach process to shared memory attachSharedMemory(); srand(time(NULL)); // Generate random seed pthread_t threads[totalThreads]; // Allocate pellet threads for(int i = 0; i < totalThreads; i++) { // Sleep for random interval between 1 and 2 seconds int sleepTime = rand() % 2 + 1; sleep(sleepTime); /* Generate random position in stream where another pellet doesn't currently exist */ int xPos, yPos; do { xPos = rand()%8+1; yPos = rand()%8+1; } while((*water)[xPos][yPos] == 'o'); // Do nothing while maxThreadsAlive threads exist int aliveThreads; do { aliveThreads = 0; for(int j = 0; j < totalThreads; j++) { if(pthread_kill(threads[j], 0) == 0) aliveThreads++; } } while(aliveThreads > maxThreadsAlive); // Spawn new pellet thread int position[2] = {xPos, yPos}; pthread_create(&threads[i], NULL, child, position); } pthread_join(threads[totalThreads-1], NULL); shmdt(water); printf("PID %d (pellet) exited because last thread died\n", getpid()); exit(0); }
static void init() { struct sigaction sigactionUSR, sigactionCHLD; //associer le signal SIGCHLD a son handler sigactionCHLD.sa_sigaction = &sigChldHandler; sigemptyset(&(sigactionCHLD.sa_mask)); sigactionCHLD.sa_flags = SA_SIGINFO; sigaction(SIGCHLD, &sigactionCHLD, NULL); //associer le signal SIGUSR2 a son handler sigactionUSR.sa_handler = &sigUsr2Handler; sigemptyset(&(sigactionUSR.sa_mask)); sigaddset(&(sigactionUSR.sa_mask), SIGCHLD); // on recoit SIGUSR2 une seule fois avant destruction de ce processus sigactionUSR.sa_flags = SA_RESETHAND; sigaction(SIGUSR2, &sigactionUSR, NULL); //initialistion des ID des resources partagees initId(); //attachement des memoires partagees attachSharedMemory(); }