int main(int argc, char *argv[]){ int iter = 0; /* identifiant du segment de memoire partage */ int shmid; if(argc != 2){ printf("Error :\t ./v4 nber_iteration\n"); exit(EXIT_FAILURE); } iter = atoi(argv[1]); /* creation zone memoire */ shmid = create_shm(100,"key",1); /* creation des processus */ switch(fork()){ case -1 : error("Creation fils", ERR_CREAT_FILS); case 0 : /* on est dans le fils */ incremente(iter, shmid); default : break; } decremente(iter, shmid); /*on attends la fin des processus */ printf("Le pere attend la mort de son fils\n") ; wait(0); printf("Bon, faisons le menage et supprimons le segment partagee\n") ; /*destruction du segment de memoire */ delete_shm(shmid); printf("Le pere se suicide\n") ; return 0; }
void signal_vector( int sig ) { delete_shm(); XUnmapWindow( xskin_d, xskin_w ); XFlush(xskin_d); XDestroyWindow( xskin_d, xskin_w ); XCloseDisplay( xskin_d ); exit (0); }
// Removes a ProcessInfo structure for a given PID // // This function iterates through all internal ProcessInfo // structures and finds a pointer to the one that represents // the PID passed in. That structure is deleted // // @param[in] pid The PID of the process we no longer // need to track void MathildaFork::remove_child_pid(pid_t pid) { ProcessInfo *p = process_info_pid(pid); if(p != NULL) { delete_shm(p); } auto it = std::remove_if(children.begin(), children.end(), [pid](ProcessInfo *p) { return p->pid == pid; } ); children.erase(it, children.end()); }
int main(int argc, char const *argv[]) { int i; int shm_id; pid_t pid; char *map_buf1; char *map_buf2; shm_id = get_shm(); // 创建一个共享内存段,并返回一个id标识符 pid = fork(); if(pid < 0) { perror("Create New Process Error"); exit(EXIT_FAILURE); }else if(pid == 0) { /*在子进程中*/ map_buf1 = at_shm(shm_id); // 将共享内存段连接到子进程中,并使map_buf1指向共享内存段 i = 0; while(i < _SHM_SIZE_) { map_buf1[i] = '8'; i++; } map_buf1[_SHM_SIZE_-1] = '\0'; rm_shm(map_buf1); // 分离子进程与共享内存 }else { /*在父进程中*/ map_buf2 = at_shm(shm_id); // 将共享内存连接到父进程中,并使map_buf2指向共享内存段 sleep(5); printf("In Parent, read Share Memory: %s\n", map_buf2); rm_shm(map_buf2); // 分离父进程与共享内存 waitpid(pid, NULL, 0); // 等待子进程结束 delete_shm(shm_id); // 删除共享内存 } return 0; }
void loop(void *arg){ RT_HEAP sampling_heap; Matrix outputMatrix=empty_matrix(1,1); long* current_period; int create; //This works as a global variable current_period=(long*) create_shm(&sampling_heap,"tickPeriod",sizeof(long),&create); *current_period=gs->sampling_period*1000; if(*current_period<SAFEZONE) *current_period=SAFEZONE; rt_task_set_periodic(NULL, TM_NOW,*current_period); while(running){ rt_task_wait_period(NULL); debug_get_start_time(); //XL forces this block to have inputs, //so we force the count to zero to ignore it io.input_num = 0; debug_store_inputs(); write_output_queues(&outputMatrix); debug_write_queue(); outputMatrix.matrix[0][0]++; //Change period if changed in GUI if(*current_period!=gs->sampling_period*1000){ *current_period=gs->sampling_period*1000; if(*current_period<SAFEZONE) *current_period=SAFEZONE; rt_task_set_periodic(NULL, TM_NOW,*current_period); } } delete_shm(&sampling_heap,current_period); }