/* Run all solutions */ int run_all(pe_data_t* pedata) { for(int i=1;i<=NUM_PROBLEMS;i++) run_solution(pedata,i); return 0; }
/* Usage will ProjectEuler N, where N is the problem number to run */ int main(int argc, char *argv[]) { pe_data_t pedata ; int ProblemNumber = 0; if (argc != 2) { printf("Not enough arguments, or too many arguments.\n"); printf("Proper usage is: ./ProjectEuler #, where # is the problem number to run\n"); } else { // Configure parameters ProblemNumber = atoi(argv[1]); pedata.verbosity = 0 ; // change to > 0 for verbose outputs // Check and run solution if ( ProblemNumber == 0) run_all(&pedata); else if (ProblemNumber <= NUM_PROBLEMS) run_solution(&pedata,ProblemNumber); else printf("Problem #%03d not found.\n", ProblemNumber); } return 0; }
int main(int argc, char *argv[]) { int compiled_ok, status; pid_t pid; int flag; compiled_ok = compile("./tmp.c"); if (compiled_ok != 0) { fprintf(stderr, "compile error\n"); exit(1); } else { printf("compile ok: %d\n", compiled_ok); } flag = AC; pid = fork(); if (pid < 0) { perror("fork error"); exit(1); } else if (pid == 0) { run_solution(work_dir); } else { watch_solution(pid, &flag); if (flag == AC) { printf("ac\n"); } else if (flag == WA) { printf("wa\n"); } else if (flag == TL) { printf("tl\n"); } else if (flag == OL) { printf("ol\n"); } else if (flag == RE) { printf("re\n"); } else if (flag == CE) { printf("ce\n"); } else if (flag == ML) { printf("ml\n"); } return 0; } }
int main(int argc, char *argv[], char *envp[]) { if (nice(10) == -1) { // increase nice value(decrease pripority) FM_LOG_WARNING("increase nice value failed: %s", strerror(errno)); } init(); parse_arguments(argc, argv); if (geteuid() == 0) { // effective user is not root FM_LOG_FATAL("please do not run as root, run as judge"); exit(EXIT_PRIVILEGED); } if (EXIT_SUCCESS != chdir(oj_solution.work_dir)) { // change current directory FM_LOG_FATAL("chdir(%s) failed: %s", oj_solution.work_dir, strerror(errno)); exit(EXIT_CHDIR); } FM_LOG_DEBUG("\n\x1b[31m----- Power Judge 1.0 -----\x1b[0m"); judge_time_limit += oj_solution.time_limit; judge_time_limit *= get_num_of_test(); if (EXIT_SUCCESS != malarm(ITIMER_REAL, judge_time_limit)) { FM_LOG_FATAL("set alarm for judge failed: %s", strerror(errno)); exit(EXIT_VERY_FIRST); } if (signal(SIGALRM, timeout_hander) == SIG_ERR) { // install signal hander for timeout FM_LOG_FATAL("cannot handle SIGALRM"); exit(EXIT_VERY_FIRST); } init_connet(); compile(); run_solution(); close_connet(); return 0; }
int main(int argc, char *argv[]) { int ret, status; pid_t pid; int flag; char user_name[128]; char work_dir[WORK_DIR_LEN]; if (argc != 3) { write_log(APP_LOG, 0, "usgae: ./main username code_id"); exit(-1); } if (atexit(remove_files) != 0) { write_log(APP_LOG, 1, "atexit error"); exit(-1); } if (atexit(update_ret_to_db) != 0) { write_log(APP_LOG, 1, "atexit error"); exit(-1); } umask(0); strcpy(user_name, argv[1]); strcpy(code_id, argv[2]); make_work_dir(user_name, work_dir); if (chdir(work_dir) < 0) { write_log(APP_LOG, 0, "chdir to wrok_dir error"); exit(-1); } init_remove_files(); init_create_files(); //sleep(5); get_code_text(code_id); get_data_input(code_id); #ifdef DEBUG //FILE *fp = fopen(DATA_IN, "w"); //fputs("1", fp); //fclose(fp); #endif ret = compile(USER_CODE); if (ret != COMPILED_OK) { write_log(LOG, 0, "compile error, see the ce.out"); exit(-1); } else { write_log(LOG, 0, "compile ok, now start run"); if (chown("./compiled_file", USER_ID, USER_ID) < 0) { write_log(INT_RE, 1, "chown compiled_file error"); exit(-1); } } pid = fork(); if (pid < 0) { write_log(INT_RE, 1, "fork error (in main)"); exit(-1); } else if (pid == 0) { run_solution(work_dir); } else { //parent watch_solution(pid, &flag); if (flag == CODE_TL) { write_log(RE, 0, "time exceed"); } else if (flag == CODE_ML) { write_log(RE, 0, "mem exceed"); } else if (flag == CODE_OL) { write_log(RE, 0, "output exceed"); } else if (flag == CODE_RE) { write_log(RE, 0, "runtime error"); } return 0; } }