/* I reconnected to the server */ TEG_STATUS clitok_reconnect( char *str) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { strncpy( g_game.myname, p.token, sizeof(g_game.myname)-1); g_game.myname[sizeof(g_game.myname)-1]=0; } else goto error; if( parser_call( &p ) && p.hay_otro ) { g_game.numjug = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { g_game.mycolor = atoi( p.token ); } else goto error; ESTADO_SET(PLAYER_STATUS_IDLE); textmsg( M_IMP,_("Successful reconnection. I'm player number:%d"),g_game.numjug ); { /* insert myself in the list of players */ CPLAYER j; PCPLAYER pJ; if( player_whois( g_game.numjug, &pJ ) != TEG_STATUS_SUCCESS ) { memset(&j,0,sizeof(j)); j.color = g_game.mycolor; j.numjug = g_game.numjug; strncpy(j.name,g_game.myname,sizeof(j.name)-1); j.name[sizeof(j.name)-1]=0; player_ins(&j); } } out_status(); out_countries(); out_enum_cards(); out_get_typeofgame(); out_new_round(); gui_reconnected(); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_reconnect()"); return TEG_STATUS_ERROR; }
int main(void){ int status; pid_t pid; if(( pid = fork() ) < 0 ){ perror("fork error"); exit(1); } else if( pid == 0 ){ printf("children pid: %d ppid: %d\n", getpid(), getppid() ); exit(3); } wait(&status); out_status(status); if(( pid = fork() ) < 0 ){ perror("fork error"); exit(1); } else if( pid == 0 ){ printf("children pid: %d ppid: %d\n", getpid(), getppid() ); int a = 5 , b = 0; int c = a / b; } wait(&status); out_status(status); if(( pid = fork() ) < 0 ){ perror("fork error"); exit(1); } else if( pid == 0 ){ printf("children pid: %d ppid: %d\n", getpid(), getppid() ); while(1){ //用kill命令杀死 } } wait(&status); out_status(status); return 0; }
/* who am i, and available colors */ TEG_STATUS clitok_playerid( char *str) { char c[TEG_MAX_PLAYERS]; PARSER p; int i; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { strncpy( g_game.myname, p.token, sizeof(g_game.myname)-1); g_game.myname[sizeof(g_game.myname)-1]=0; } else goto error; if( parser_call( &p ) && p.hay_otro ) { g_game.numjug = atoi( p.token ); } else goto error; for(i=0;i<TEG_MAX_PLAYERS-1;i++ ) { if( parser_call( &p ) && p.hay_otro ) { c[i] = atoi( p.token ); } else goto error; } if( parser_call( &p ) && !p.hay_otro ) { c[i] = atoi( p.token ); } else goto error; ESTADO_SET(PLAYER_STATUS_CONNECTED); out_status(); if( g_game.observer ) out_countries(); gui_connected( c ); textmsg( M_IMP,_("I'm player number:%d"),g_game.numjug ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_playerid()"); return TEG_STATUS_ERROR; }