static void showtop(int cputimemode, int r) { #define NLOADS 3 double loads[NLOADS]; int nloads, lines = 0; struct winsize winsize; if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) { perror("TIOCGWINSZ"); fprintf(stderr, "TIOCGWINSZ failed\n"); exit(1); } get_procs(); if (prev_proc == NULL) get_procs(); if((nloads = getloadavg(loads, NLOADS)) != NLOADS) { fprintf(stderr, "getloadavg() failed - %d loads\n", nloads); exit(1); } printf("%s", Tclr_all); lines += print_load(loads, NLOADS); lines += print_proc_summary(proc); lines += print_memory(); if(winsize.ws_row > 0) r = winsize.ws_row; print_procs(r - lines - 2, prev_proc, proc, cputimemode); fflush(NULL); }
void game_loop(t_env *e) { int before_check_die; before_check_die = 0; print_board(e); refresh(); while (e->nb_proc_in_life > 0 && e->nb_cycle < e->nb_cycle_max) { ++e->nb_cycle; if (before_check_die >= e->c_to_die) { check_champ_cycle(e); check_proc_cycle(e); before_check_die = 0; if (e->nb_proc_in_life == 0) return ; } ++before_check_die; if (e->verbose & VERBOSE_CYCLE) ft_printf("It is now cycle %d\n", e->nb_cycle); proc_loop(e); if (have_opt('c', e->opt)) ncurses_loop(e); } if (!have_opt('c', e->opt) && have_opt('d', e->opt)) print_memory(e->mem); }
static void cleanup(void) { LOG_WARNING("Terminating"); message_post_shutdown(); message_cleanup(); if(group) select_group_destroy(group); if(driver_console) driver_console_destroy(driver_console); if(driver_command) driver_command_destroy(driver_command); if(driver_dns) driver_dns_destroy(driver_dns); if(driver_exec) driver_exec_destroy(driver_exec); if(driver_listener) driver_listener_destroy(driver_listener); if(driver_ping) driver_ping_destroy(driver_ping); print_memory(); }
int main() { int action; double *pointer; while(1) { show_menu(); scanf("%d", &action); switch(action) { case 0: exit(0); break; case 1: pointer = allocate_memory(); break; case 2: fill_memory(pointer); break; case 3: print_memory(pointer); break; case 4: free(pointer); break; } } }
/* Use this function to see what happens when your malloc and free * implementations are called. Run "mem -try <args>" to call this function. * We have given you a simple example to start. */ void try_mymem(int argc, char **argv) { strategies strat; void *a, *b, *c, *d, *e; if(argc > 1) strat = strategyFromString(argv[1]); else strat = First; /* A simple example. Each algorithm should produce a different layout. */ initmem(strat,500); a = mymalloc(100); b = mymalloc(100); c = mymalloc(100); myfree(b); d = mymalloc(50); myfree(a); e = mymalloc(25); print_memory(); print_memory_status(); }
void test_routine() { pid_t *ptrs[NUM_ALLOC], pid; int i; pid = getpid(); printf("my_pid is %d\n", pid); srand(pid); for(i = 0; i < NUM_ALLOC; i++) { ptrs[i] = shm_malloc(rand() % MAX_ALLOC_SIZE); if(ptrs[i]) { *ptrs[i] = pid; } sleep(rand() % 2); } print_memory(); for(i = 0; i < NUM_ALLOC; i++) { if(ptrs[i]) { printf("#%d == %d: ", pid, *ptrs[i]); printf("%s\n", *ptrs[i] == pid ? "true" : "false"); shm_free(ptrs[i]); sleep(rand() % 2); } } }
int main() { shm_malloc_init(); run_test(); print_memory(); shm_malloc_clean(); return 0; }
void showtop(int r) { #define NLOADS 3 double loads[NLOADS]; int nloads, i, p, lines = 0; static struct proc prev_proc[PROCS], proc[PROCS]; struct winsize winsize; static struct pm_mem_info pmi; static int prev_uptime, uptime; static struct mproc mproc[NR_PROCS]; struct tms tms; uptime = times(&tms); if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) { perror("TIOCGWINSZ"); fprintf(stderr, "TIOCGWINSZ failed\n"); exit(1); } if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) { fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n"); exit(1);; } if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) { fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n"); exit(1); } if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) { fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n"); exit(1); } if((nloads = getloadavg(loads, NLOADS)) != NLOADS) { fprintf(stderr, "getloadavg() failed - %d loads\n", nloads); exit(1); } printf("%s", Tclr_all); lines += print_load(loads, NLOADS); lines += print_proc_summary(proc); lines += print_memory(&pmi); if(winsize.ws_row > 0) r = winsize.ws_row; print_procs(r - lines - 2, prev_proc, proc, uptime-prev_uptime, mproc); memcpy(prev_proc, proc, sizeof(prev_proc)); prev_uptime = uptime; }
int main(void) { int tab[9] = {0, 23, 150, 255, 12, 16, 21, 42}; char tab2[] = {'3', 'b', 'w'}; char tab3[] = {'3', 'b', 'w', 0}; char tab4[256]; char tab5[1] = {42}; char tab6[15] = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69}; char tab7[16] = {48, 0, 50, 0, 52, 53, 54, 0, 56, 57, 0, 66, 67, 68, 69, 70}; int tab8[] = {13, 2, 4}; int tab9[] = {14}; int tab10[] = {65, 125, 35, 32, 120, 40}; int i; i = 0; while (i < 256) { tab4[i] = i; ++i; } printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab)); print_memory(tab, sizeof(tab)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab4)); print_memory(tab4, sizeof(tab4)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab2)); print_memory(tab2, sizeof(tab2)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab3)); print_memory(tab3, sizeof(tab3)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab5)); print_memory(tab5, sizeof(tab5)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab6)); print_memory(tab6, sizeof(tab6)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab7)); print_memory(tab7, sizeof(tab7)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab8)); print_memory(tab8, sizeof(tab8)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab9)); print_memory(tab9, sizeof(tab9)); printf("\n\t ==========size:%d==================\n\n", (int)sizeof(tab10)); print_memory(tab10, sizeof(tab10)); return (0); }
int main(void) { char *** test = alloc_memory(16,32); while(1){ zero_memory(16,32,test); initialize_random(16,32,test); mutate(16,32,test); print_memory(16,32,test); } }
static void measure_one_cycle(void) { struct timespec ts1, ts2, delta, sleep; int rc; current_sum_utime = 0; current_sum_stime = 0; current_sum_cpu_utime = 0; current_sum_cpu_stime = 0; if (nr_cycles) output->print_cycle_start(); else output->print_sync(); new_cycle = 1; rc = clock_gettime(CLOCK_MONOTONIC, &ts1); if (rc < 0) DIE_PERROR("clock_gettime failed"); query_tasks(); query_memory(); query_cpus(opt_all_cpus); print_tasks(); print_memory(); print_cpus(opt_all_cpus); rc = clock_gettime(CLOCK_MONOTONIC, &ts2); if (rc < 0) DIE_PERROR("clock_gettime failed"); timespec_delta(&ts1, &ts2, &delta); if (nr_cycles) output->print_cycle_end(&delta); /* check if we can meet the target measurement interval */ if (delta.tv_sec > target.tv_sec || (delta.tv_sec == target.tv_sec && delta.tv_nsec > target.tv_nsec)) { output->exit_output(); DIE("Target measurement intervall too small. Current overhead: %u seconds %lu ms\n", (int) delta.tv_sec, delta.tv_nsec / NSECS_PER_MSEC); } /* now go sleeping for the rest of the measurement interval */ if (nr_cycles) timespec_delta(&delta, &target, &sleep); else timespec_delta(&delta, &ts_sync, &sleep); wait_for_cycle_end(&sleep); nr_cycles++; }
int main(int argc, const char *argv[]) { packet_t *packet; uint8_t *bytes; size_t length; /* Create a SYN */ packet = packet_create_syn(0x1234, 0x0000, 0x0000); packet_print(packet); /* Convert it to bytes and free the original */ bytes = packet_to_bytes(packet, &length); packet_destroy(packet); /* Parse the bytes from the old packet to create a new one */ packet = packet_parse(bytes, length); packet_print(packet); packet_destroy(packet); safe_free(bytes); /* Create a MSG */ packet = packet_create_msg(0x1234, 0x0000, 0x0001, (uint8_t*)"AAAAA", 5); packet_print(packet); /* Convert it to bytes and free the orignal */ bytes = packet_to_bytes(packet, &length); packet_destroy(packet); /* Parse the bytes from the old packet to create a new one */ packet = packet_parse(bytes, length); packet_print(packet); packet_destroy(packet); safe_free(bytes); /* Create a FIN */ packet = packet_create_fin(0x1234); packet_print(packet); /* Convert it to bytes and free the orignal */ bytes = packet_to_bytes(packet, &length); packet_destroy(packet); safe_free(bytes); /* Parse the bytes from the old packet to create a new one */ packet = packet_parse(bytes, length); packet_print(packet); packet_destroy(packet); print_memory(); return 0; }
int main(void) { FILE *fp_mail; char *status = (char *)alloca(200); int b, d, m; b = BATTERY_INTERVAL; d = DATE_INTERVAL; m = MAIL_INTERVAL; struct timespec interval = { .tv_sec = UPDATE_INTERVAL, .tv_nsec = 0 }; int sockfd = socket(AF_INET, SOCK_DGRAM, 0); for ( ; ; nanosleep(&interval, NULL)) { if (++b > BATTERY_INTERVAL) { print_battery(); b = 0; } if (++d > DATE_INTERVAL) { print_time(); d = 0; } if (++m > MAIL_INTERVAL) { if (print_mail(fp_mail) == 0) { m = 0; } if (errno == EBADF) { fp_mail = mail_init(); } } if (sockfd != -1) { print_iw(sockfd); } strncpy(_root, print_free("/"), _FREE_LEN); strncpy(_home, print_free("/home"), _FREE_LEN); print_time(); print_cpu(); print_memory(); snprintf(status, 200, "%s %s | %s | %s | %s | %s | %s | %s" , _root, _home, _iw, _battery, _mail, _cpu , _mem, _date); printf("%s\n", status); }//break; } pclose(fp_mail); cleanup(sockfd); } double get_battery_stats(const char *path) { FILE *stats; double value = 0; if ((stats = fopen(path, "r"))== NULL) { return -1; } fscanf(stats, "%lf", &value); fclose(stats); return value; }
static void cleanup(void) { printf("Cleaning up...\n"); if(global_settings) { if(global_settings->group) select_group_destroy(global_settings->group); safe_free(global_settings); } /* Print allocated memory. This will only run if -DTESTMEMORY is given. */ print_memory(); }
void Summary::print() { print_versions(); print_memory(); print_cpu(); print_threads(); print_pools(); # ifndef XMRIG_NO_API print_api(); # endif print_commands(); }
static void show(int len, size_t *total) { size_t start_heap[len]; int i; ft_bzero(start_heap, sizeof(size_t) * len); get_start_heap(start_heap, g_base[TINY]); get_start_heap(start_heap, g_base[SMALL]); get_start_heap(start_heap, g_base[LARGE]); size_t_sort(start_heap, len); i = 0; while (i < len) print_memory((t_block *)start_heap[i++], total); }
main() { uint8_t *memory1, *memory2; REDLED=0; AUXR=0x0c; // make all of XRAM available, ALE always on if(OSC_PER_INST==6) { CKCON0=0x01; // set X2 clock mode } else if(OSC_PER_INST==12) { CKCON0=0x00; // set standard clock mode } uart_init(); DELAY_1ms_T1(300); REDLED=1; memory1=code_memory_init(); memory2=xdata_memory_init(); print_memory(memory1, 41); putchar(CR); putchar(LF); print_memory(memory2, 42); putchar(CR); putchar(LF); LCD_Init(); Update_Line1(); Update_Line2(); while(1) { } }
static void cleanup(void) { LOG_WARNING("Terminating"); controller_destroy(); if(tunnel_driver) driver_dns_destroy(tunnel_driver); if(group) select_group_destroy(group); if(system_dns) safe_free(system_dns); print_memory(); }
void cleanup() { LOG_INFO("[[tcpcat]] :: Terminating"); if(options) { session_destroy(options->session, options->group); /* Ensure the options is closed */ if(options->s != -1) tcpcat_close(options); buffer_destroy(options->buffer); safe_free(options); options = NULL; } print_memory(); }
int main(int argc, char *argv[]) { int i; if(argc==1) { printf("Argument required. To use default memory, enter '0', to set\n your own memory, enter any other argument\n"); return 0; } //if no argument is given in the command line, program prints error //message and terminates if(strcmp(argv[1],"0") == 0) set_memory(); //if argument given is 0, program calls set_memory() to run using //default memory settings else if(strcmp(argv[1],"0") != 0) read_memory(); //if some nonzero argument is entered, program calls read_memory, //prompting the user to enter starting memory values //byte-by-byte while(pc<MEM_SIZE) { strcpy(ir, memory[pc]); pc++; execute(); //loads memory next piece of memory into the IR, increments the PC, and //executes the command found in the designated memory space. if(halt) break; //if the command executed in memory is the "halt" command, program stops //going through memory. } printf("Memory:\n"); print_memory(); printf("Accumulator:\n"); printf("%s\n",ac); //prints values in accumulator and memory return 0; }
int main() { int action; char **pointer; pointer = malloc(5 * sizeof(char *)); pointer[0] = "asd"; pointer[1] = "123"; pointer[2] = "lald"; pointer[3] = "mnmn"; pointer[4] = END_OF_ARRAY; while(1) { show_menu(); scanf("%d", &action); switch(action) { case 0: exit(0); break; case 1: pointer = allocate_memory(); break; case 2: fill_memory(pointer); break; case 3: replace_memory(pointer); break; case 4: reverse_array(pointer); break; case 5: break; case 6: print_memory(pointer); break; } } }
int main(int argc, char *argv[]) { FILE *fp, *fp2; char buf[100000][100]; /*命令 読み込み用バッファ */ char fpt[FPT_MAX_COUNT][20] = { 0 }; char ofname[1000] = "result"; int i = 0, j, k; //メモリ上の浮動小数点テーブルの位置 int fpmemoffset = 0; int result; bool doprintregs = false, doprintmem = false; program *answer; program2 *answer2; double t2, t1; int ll = 0; while ((result = getopt(argc, argv, "rmo:")) != -1) { switch (result) { /* 値をとらないオプション */ case 'r': /* getoptの返り値は見付けたオプションである. */ doprintregs = true; break; case 'm': doprintmem = true; break; case 'o': /* 値を取る引数の場合は外部変数optargにその値を格納する. */ strcpy(ofname, optarg); break; /* 以下二つのcaseは意味がないようだ. getoptが直接エラーを出力してくれるから. プログラムを終了するなら意味があるかも知れない */ case ':': /* 値を取る引数に値がなかった場合:を返す. */ fprintf(stdout, "%c needs value\n", result); break; /* getoptの引数で指定されなかったオプションを受け取ると?を返す. */ case '?': fprintf(stdout, "unknown\n"); break; } } argc -= optind; argv += optind; /* if (argc < 3) { fprintf(stderr, "<Useage>:%s assembler-file fp-table-file\n", argv[0]); return 1; } */ /*assembler-file open and read */ fp = fopen(argv[0], "r"); if (fp == NULL) { printf("%sが開けませんaa\n", argv[0]); return 1; } if (argc > 1) { fp2 = fopen(argv[1], "r"); if (fp2 == NULL) { printf("%sが開けません\n", argv[1]); return 1; } for (i = 0; i < FPT_MAX_COUNT; ++i) { if (fgets(fpt[i], 20, fp2) == NULL) { /* 1行読み込み */ break; /* 末尾まで完了したか、エラー発生で終了 */ } } for (j = 0; j < i; ++j) { //エラーが起こっても関係ない //printf("%s\n", fpt[j]); memory[j + fpmemoffset].i = (int) strtoll(fpt[j], NULL, 16); } //print_memory(); } i = 0; while (1) { if (fgets(buf[i], 81, fp) == NULL) { /* 1行読み込み */ break; /* 末尾まで完了したか、エラー発生で終了 */ } i++; } out_fp = fopen(ofname, "w"); answer = parse_all(buf, i); answer2 = parse_all2(answer); //print_program(answer); t1 = gettimeofday_sec(); //do_assemble(answer); do_assemble2(answer, answer2); t2 = gettimeofday_sec(); printf("%lf\n", t2 - t1); if (doprintregs) print_register(); if (doprintmem) print_memory(); fclose(fp); fclose(fp2); fclose(out_fp); printf("%f\n", ppp); printf("%f\n", nnn); /* fprintf(fp, "P3\n%d %d %d\n", memory[8193].i, memory[8194].i, memory[8195].i); for (i = 8196; i < memory[8192].i; i = i + 3) { fprintf(fp, "%d %d %d\n", (int) memory[i].d, (int) memory[i + 1].d, (int) memory[i + 2].d); } */ return 0; }
int do_assemble2(program *program, program2 * program2) { int pc = 0; int nextpc = 0; long long counter = 0; instruction2 ist; int iname, arg1, arg2, arg3; while (1) { pc = nextpc; ist = program2->insts[pc]; iname = ist.name[0]; arg1 = ist.name[1]; arg2 = ist.name[2]; arg3 = ist.name[3]; /* ++counter; if(counter > 575600 && counter < 575719) { print_label_from_index(program, pc); print_instruction(program->insts[pc]); print_register(); } */ if (iname == 0) { // printf("this is nop\n"); } DO_INST_1(1, +) DO_INST_1(2, -) DO_INST_1(3, *) DO_INST_1(4, &) DO_INST_1(5, |) /*ALU命令 */ else if (iname == 6) { regist[ist.name[1]] = ~(regist[ist.name[2]] | regist[ist.name[3]]); } else if (iname == 7) { regist[ist.name[1]] = regist[ist.name[2]] ^ regist[ist.name[3]]; } else if (iname == 8) { regist[ist.name[1]] = regist[ist.name[2]] + ist.name[3]; } else if (iname == 9) { regist[ist.name[1]] = regist[ist.name[2]] - ist.name[3]; } else if (iname == 10) { regist[ist.name[1]] = regist[ist.name[2]] * ist.name[3]; } else if (iname == 11) { regist[ist.name[1]] = regist[ist.name[2]] & ist.name[3]; } else if (iname == 12) { regist[ist.name[1]] = regist[ist.name[2]] | ist.name[3]; } else if (iname == 13) { regist[ist.name[1]] = ~(regist[ist.name[2]] | ist.name[3]); } else if (iname == 14) { regist[ist.name[1]] = regist[ist.name[2]] ^ ist.name[3]; } /*FPU命令 */ else if (iname == 15) { freg[ist.name[1]] = freg[ist.name[2]] + freg[ist.name[3]]; } else if (iname == 16) { freg[ist.name[1]] = freg[ist.name[2]] - freg[ist.name[3]]; } else if (iname == 17) { freg[ist.name[1]] = freg[ist.name[2]] * freg[ist.name[3]]; } else if (iname == 18) { freg[ist.name[1]] = freg[ist.name[2]] / freg[ist.name[3]]; } else if (iname == 19) { freg[ist.name[1]] = 1 / freg[ist.name[2]]; } else if (iname == 20) { freg[ist.name[1]] = sqrt(freg[ist.name[2]]); } else if (iname == 21) { freg[ist.name[1]] = floor(freg[ist.name[2]]); } else if (iname == 22) { freg[ist.name[1]] = (float) (regist[ist.name[2]]); } /*MEM ACSESS命令 */ else if (iname == 23) { //memory_check if (check_memory(regist[ist.name[2]] + ist.name[3]) == ACSESS_BAD) { printf("Error:ACSESS_BAD :\n"); // printf("%d\n", iname); //printf("%lld\n", counter); exit(1); } regist[ist.name[1]] = memory[regist[ist.name[2]] + ist.name[3]].i; } else if (iname == 24) { //memory_check if (check_memory(regist[ist.name[2]] + ist.name[3]) == ACSESS_BAD) { printf("Error:ACSESS_BAD :\n"); //printf("%d\n", iname); exit(1); } memory[regist[ist.name[2]] + ist.name[3]].i = regist[ist.name[1]]; } else if (iname == 25) { //memory_check if (check_memory(regist[ist.name[2]] + ist.name[3]) == ACSESS_BAD) { printf("Error:ACSESS_BAD :\n"); //printf("%d\n", iname); exit(1); } freg[ist.name[1]] = memory[regist[ist.name[2]] + ist.name[3]].d; } else if (iname == 26) { //memory_check if (check_memory(regist[ist.name[2]] + ist.name[3]) == ACSESS_BAD) { printf("Error:ACSESS_BAD :\n"); // printf("%d\n", iname); exit(1); } memory[regist[ist.name[2]] + ist.name[3]].d = freg[ist.name[1]]; } /*BRANCH命令 */ else if (iname == 27) { if (regist[ist.name[1]] == regist[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 28) { if (regist[ist.name[1]] != regist[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 29) { if (regist[ist.name[1]] > regist[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 30) { if (regist[ist.name[1]] < regist[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 31) { if (regist[ist.name[1]] >= regist[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 32) { if (regist[ist.name[1]] <= regist[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 33) { if (freg[ist.name[1]] == freg[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 34) { if (freg[ist.name[1]] != freg[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 35) { if (freg[ist.name[1]] > freg[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 36) { if (freg[ist.name[1]] < freg[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 37) { if (freg[ist.name[1]] >= freg[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } else if (iname == 38) { if (freg[ist.name[1]] <= freg[ist.name[2]]) { nextpc = pc + ist.name[3] - 1; } } /*JUMP命令 */ else if (iname == 39) { if (ist.name[1] == -100) { freg[2] = atanf(freg[2]); nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -200) { freg[2] = sqrtf(freg[2]); nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -300) { regist[4] = read_int(); printf("read_int: %d\n", regist[4]); nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -400) { freg[2] = read_float(); printf("read_float: %f\n", freg[2]); nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -500) { printf("aaa\n"); if(ppp < freg[2]) { ppp = freg[2]; } if(nnn > freg[2]) { nnn = freg[2]; } //print_register(); nextpc = label_trans(program->insts[pc].name[1], program) - 1; //freg[2] = sinf(freg[2]); //printf("read_float: %f\n", freg[2]); //nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -600) { freg[2] = cosf(freg[2]); //printf("read_float: %f\n", freg[2]); nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -700) { //print_int print_int(); nextpc = pop(&call_stack) - 1; } else if (ist.name[1] == -800) { print_float(); nextpc = pop(&call_stack) - 1; } else { nextpc = ist.name[1] - 1; } /* if(strncmp(program->insts[pc].name[1] , "L_main", 6) == 0) { print_memory(); } */ } else if (iname == 40) { nextpc = ist.name[1] - 1; /*特殊ラベル*/ if (ist.name[1] == -100) { freg[2] = atanf(freg[2]); nextpc = pc; } else if (ist.name[1] == -200) { freg[2] = sqrtf(freg[2]); nextpc = pc; } else if (ist.name[1] == -300) { regist[4] = read_int(); printf("read_int: %d\n", regist[4]); nextpc = pc; } else if (ist.name[1] == -400) { freg[2] = read_float(); printf("read_float: %f\n", freg[2]); nextpc = pc; } else if (ist.name[1] == -500) { printf("aab\n"); kkk = 1; if(ppp < freg[2]) { ppp = freg[2]; } if(nnn > freg[2]) { nnn = freg[2]; } push(&call_stack, (pc + 1)); nextpc = label_trans(program->insts[pc].name[1], program) - 1; //freg[2] = sinf(freg[2]); //printf("read_float: %f\n", freg[2]); //nextpc = pc; } else if (ist.name[1] == -600) { freg[2] = cosf(freg[2]); //printf("read_float: %f\n", freg[2]); nextpc = pc; } else if (ist.name[1] == -700) { //print_int print_int(); nextpc = pc; } else if (ist.name[1] == -800) { print_float(); nextpc = pc; } else { push(&call_stack, (pc + 1)); } } else if (iname == 41) { nextpc = pop(&call_stack) - 1; } else if (iname = 42) { print_register(); print_memory(); } //命令が存在しなかった場合error parseでやっているのでいらない。 //printf("ist = %d\n",iname); nextpc++; /*命令がラストの行まで行けば処理を終了する */ if (nextpc >= program2->inst_count) { break; } } return 0; }
int main(){ int *a, *b, *c, *d, *f, *g, *h, *i, *j, *k, *l, *m; printf("Adding 10 nodes..\n"); a = cust_malloc(sizeof(int)); b = cust_malloc(sizeof(int)); c = cust_malloc(sizeof(int)); d = cust_malloc(sizeof(int)); f = cust_malloc(sizeof(int)); g = cust_malloc(sizeof(int)); h = cust_malloc(sizeof(int)); i = cust_malloc(sizeof(int)); j = cust_malloc(sizeof(int)); k = cust_malloc(sizeof(int)); print_memory(); printf("\nClearing a node before the end and then removing end, for 8 nodes left..\n"); cust_free(j); cust_free(k); print_memory(); printf("\nClearing Start Node:\n"); cust_free(a); print_memory(); printf("\nClearing Node after Start, Coalescing...\n"); cust_free(b); print_memory(); printf("\nAdding Node with first search (Should be Start and splitting it).\n"); b=cust_malloc(sizeof(int)); print_memory(); printf("\n removing 3 middle nodes(closest to the end) to test 3 coalescing \n"); cust_free(f); print_memory(); printf("\n"); cust_free(h); print_memory(); printf("\n"); cust_free(g); print_memory(); printf("\n Removing 3rd Node to show forward Coalescing..\n"); cust_free(c); print_memory(); printf("\n Removing nodes one at a time...\n"); cust_free(d); print_memory(); printf("\n"); cust_free(i); print_memory(); printf("\n"); cust_free(b); print_memory(); return 0; }
void showtop(int r) { #define NLOADS 3 double loads[NLOADS]; int nloads, i, p, lines = 0; static struct proc prev_proc[PROCS], proc[PROCS]; static int preheated = 0; struct winsize winsize; /* static struct pm_mem_info pmi; */ static struct mproc mproc[NR_PROCS]; int mem = 0; if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) { perror("TIOCGWINSZ"); fprintf(stderr, "TIOCGWINSZ failed\n"); exit(1); } #if 0 if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) { fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n"); mem = 0; exit(1);; } else mem = 1; #endif retry: if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) { fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n"); exit(1); } if (!preheated) { preheated = 1; memcpy(prev_proc, proc, sizeof(prev_proc)); goto retry;; } if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) { fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n"); exit(1); } if((nloads = getloadavg(loads, NLOADS)) != NLOADS) { fprintf(stderr, "getloadavg() failed - %d loads\n", nloads); exit(1); } printf("%s", Tclr_all); lines += print_load(loads, NLOADS); lines += print_proc_summary(proc); #if 0 if(mem) { lines += print_memory(&pmi); } #endif if(winsize.ws_row > 0) r = winsize.ws_row; print_procs(r - lines - 2, prev_proc, proc, mproc); memcpy(prev_proc, proc, sizeof(prev_proc)); }
void shell(){ char c; char buffer[MAX_CMD_SIZE+1]; char last_cmd[CMD_MEMORY][MAX_CMD_SIZE+1]; int i,mem; char shell_color=0x09; char user_color=0x07; for(mem=0;mem<CMD_MEMORY;mem++){ last_cmd[mem][0]=0; } while(1){ __setcolor(&shell_color); printf("Shell->: "); __setcolor(&user_color); i=0; mem=-1; do{ c=getchar(); if(c=='\b'){ if(i>0){ i--; putchar(c); } } else if(c=='\x11'){ /*UP*/ if(mem<CMD_MEMORY-1){ mem++; int j; for(j=0;j<i;j++){ putchar('\b'); } i=strlen(last_cmd[mem]); strcpy(buffer,last_cmd[mem]); printf("%s",buffer); } } else if(c=='\x13'){ /*DOWN*/ if(mem>0){ mem--; int j; for(j=0;j<i;j++){ putchar('\b'); } i=strlen(last_cmd[mem]); strcpy(buffer,last_cmd[mem]); printf("%s",buffer); } } else if(c=='\x12'){ //do nothing } else{ if(i<MAX_CMD_SIZE||c=='\n'){ putchar(c); buffer[i]=c; i++; } } }while(c!='\n'); buffer[i-1]=0; /*GUARDAR COMANDOS ANTERIORES*/ int k; for(k=CMD_MEMORY-2;k>=0;k--){ strcpy(last_cmd[k+1],last_cmd[k]); } strcpy(last_cmd[0],buffer); if(strlen(buffer)==0){ /*VACIO*/ } else if(strcmp("who",buffer)==0){ printf("\n************\nF Alderete\nF Ramundo\nC Mader Blanco\n************\n\n"); } else if(substr("echo ", buffer)){ printf("%s\n",buffer+5); } else if(substr("color ", buffer)){ char tmp=color(buffer+6); if(tmp==0){ printf("Invalid color name\n"); } else{ user_color=tmp; } } else if(strcmp("time",buffer)==0){ int m, h; m=getmin(); h=gethour(); if(m<10){ printf("%d:0%d\n",h,m); }else{ printf("%d:%d\n",h,m); } } else if(substr("keyboard ", buffer)){ if(strcmp("ESP", buffer+9)==0){ set_scancode(1); }else if(strcmp("ENG", buffer+9)==0){ set_scancode(2); }else{ printf("Unsuported layout\n"); } } else if(substr("speak ", buffer)){ speak(buffer+6); } else if(strcmp("memstat", buffer)==0){ print_memory(); } else if(substr("memalloc ", buffer)){ i=atoi(buffer+9); if(malloc(i)!=0){ printf("Memory allocated\n"); }else{ printf("Not enough memory\n"); } } else if(substr("memcalloc ", buffer)){ i=atoi(buffer+10); if(calloc(i)!=0){ printf("Memory allocated\n"); }else{ printf("Not enough memory\n"); } } else if(substr("pageprint ", buffer)){ i=atoi(buffer+10); if(pageprint(i)==0){ printf("Invalid argument"); } } else if(substr("memfree ", buffer)){ i=atoi(buffer+8); if(free((void*)((i+530)*4096))){ printf("Memory freed\n"); } else{ printf("Invalid argument\n"); } } else if(strcmp("lostquote", buffer)==0){ printf("%s", get_quote()); } else if(strcmp("mastersword", buffer)==0){ print_zelda(); } else if(strcmp("mario", buffer)==0){ print_mario(); } else if(strcmp("help", buffer)==0){ help(); } else if(strcmp("mastermind",buffer)==0){ mastermind(); } else{ printf("Command not found\n"); } } }
int main(){ queue *test = malloc(sizeof(queue)); test->head = NULL; test->tail = NULL; queue *priority = malloc(sizeof(queue)); priority->head = NULL; priority->tail = NULL; queue *secondary = malloc(sizeof(queue)); secondary->head = NULL; secondary->tail = NULL; // node_t *priority = NULL; //queue 1 // node_t *secondary = NULL; //queue 2 /* //start temp proc *p1 = (proc *)malloc(sizeof(proc)); strcpy(p1->name,"p1"); p1->priority = 0; p1->pid = 33; p1->runtime = 5; push(&test,*p1); proc *p2 = (proc *)malloc(sizeof(proc)); strcpy(p2->name,"p2"); p2->priority = 0; p2->pid = 33; p2->runtime = 5; push(&test,*p2); proc popped = pop(&test); // print_proc(&popped); push(&test,popped); print_list(test); // pop(&test); //end temp */ readFile(&priority,0);//loads all processes with priority == 0 readFile(&secondary,1);//loads all processes with priority != 0 print_list(priority); puts("----"); //print_list(secondary); //create an array of available memory int avail_mem[TOTAL_MEMORY] = {0}; //iterate through all priority processes node_t *temp = priority->head; while (temp != NULL){ pid_t pid = fork(); if (pid == 0){ //child process puts("child:"); execlp("./process",NULL); exit(0); }else if (pid >0){ //parent process temp->val.pid = pid; //set the pid of the process //allocate the required memory int i = 0; temp->val.address = i; for (i = 0; i < temp->val.memory; i++){ avail_mem[i] = 1; } printf("[parent] Executing process: %s, priority: %d, pid: %d, memory: %d, runtime: %d\n", temp->val.name,temp->val.priority,temp->val.pid,temp->val.memory, temp->val.runtime); printf("[parent] waiting %d seconds...:\n",temp->val.runtime); sleep(temp->val.runtime); //sleep for the needed runtime puts("[parent] Sending SIGINT..."); kill(pid,SIGINT); waitpid(pid,0,0); //free the allocated memory printf("[parent] Current available memory: %dMB\n",freeMemoryAmount(avail_mem,TOTAL_MEMORY)); printf("[parent] Freeing: %dMB of memory\n",temp->val.memory); for (int j = 0; j < temp->val.memory; j++){ avail_mem[j] = 0; } //print process to be deleted printf("[parent] Deleting process: %s, priority: %d, pid: %d, runtime: %d\n", temp->val.name,temp->val.priority,temp->val.pid,temp->val.runtime); //delete process from queue temp = temp->next; pop(&priority); puts("--------------------------------------------"); }else{ //fork failed } } //iterate through all the secondary processes print_list(secondary); puts("--------------------------------------------"); int memory_index = 0; temp = secondary->head; while(temp != NULL){//while items in queue proc popped_proc = pop(&secondary);//pop the next process //check if new process and available memory if (popped_proc.suspended == 0 && popped_proc.memory <= freeMemoryAmount(avail_mem,TOTAL_MEMORY)){ //create a new process pid_t pid = fork(); if (pid == 0){ //child execlp("./process",NULL); exit(0); }else if(pid > 0){ //parent printf("Creating new process: ");print_proc(&popped_proc); //allocate the needed memory printf("ALLOCATING memory from: %d, to %d\n",memory_index,memory_index + popped_proc.memory -1); //temp popped_proc.address = memory_index; for (int i = 0; i < popped_proc.memory; i++){ avail_mem[memory_index+i] = 1; } memory_index += popped_proc.memory; printf("MEMORY_INDEX: %d\n",memory_index); print_memory(avail_mem,TOTAL_MEMORY);//temp //new process to be created sleep(1); kill(pid,SIGTSTP); popped_proc.pid = pid; //set the process id [TODO: FIX PID] popped_proc.runtime -= 1; //decrement the runtime popped_proc.suspended = 1; //update the suspended boolean //add the process back on the queue push(&secondary, popped_proc); }else{ perror("Error forking\n"); } }else if(popped_proc.suspended == 1 && popped_proc.runtime != 1){ //must continue process printf("Resuming process: ");print_proc(&popped_proc); kill(popped_proc.pid,SIGCONT); sleep(1); //sleep for once second kill(popped_proc.pid,SIGTSTP); popped_proc.runtime -= 1; //add the process back on the queue push(&secondary, popped_proc); }else if (popped_proc.runtime == 1){ //only 1 second left on process printf("One second left on Process: ");print_proc(&popped_proc); //run for the remaining second //delocate the memory taken printf("DEALLOCATING memory from %d, to %d\n",memory_index - 1, memory_index - popped_proc.memory); for (int i = 1; i <= popped_proc.memory; i++){ avail_mem[memory_index - i] = 0; } memory_index -= popped_proc.memory; printf("MEMORY_INDEX: %d\n",memory_index); print_memory(avail_mem,TOTAL_MEMORY);//temp //run the process kill(popped_proc.pid,SIGCONT); sleep(1); //sleep for once second kill(popped_proc.pid,SIGINT); waitpid(popped_proc.pid,0,0); }else { //not enough memory, push back on the queue printf("Not enough memory for: ");print_proc(&popped_proc); push(&secondary, popped_proc); } temp = secondary->head;//go to next node } puts("---------------COMPLETE--------------------"); return 0; }
static struct ebt_mac_wormhash *create_wormhash(const char *arg) { const char *pc = arg; const char *anchor; char *endptr; struct ebt_mac_wormhash *workcopy, *result, *h; unsigned char mac[6]; unsigned char ip[4]; int nmacs = 0; int i; char token[4]; if (!(workcopy = new_wormhash(1024))) { print_memory(); } while (1) { /* remember current position, we'll need it on error */ anchor = pc; /* collect MAC; all its bytes are followed by ':' (colon), * except for the last one which can be followed by * ',' (comma), '=' or '\0' */ for (i = 0; i < 5; i++) { if (read_until(&pc, ":", token, 2) < 0 || token[0] == 0) { print_error("MAC parse error: %.20s", anchor); } mac[i] = strtol(token, &endptr, 16); if (*endptr) { print_error("MAC parse error: %.20s", anchor); } pc++; } if (read_until(&pc, "=,", token, 2) == -2 || token[0] == 0) { print_error("MAC parse error: %.20s", anchor); } mac[i] = strtol(token, &endptr, 16); if (*endptr) { print_error("MAC parse error: %.20s", anchor); } if (*pc == '=') { /* an IP follows the MAC; collect similarly to MAC */ pc++; anchor = pc; for (i = 0; i < 3; i++) { if (read_until(&pc, ".", token, 3) < 0 || token[0] == 0) { print_error ("IP parse error: %.20s", anchor); } ip[i] = strtol(token, &endptr, 10); if (*endptr) { print_error ("IP parse error: %.20s", anchor); } pc++; } if (read_until(&pc, ",", token, 3) == -2 || token[0] == 0) { print_error("IP parse error: %.20s", anchor); } ip[3] = strtol(token, &endptr, 10); if (*endptr) { print_error("IP parse error: %.20s", anchor); } if (*(uint32_t*)ip == 0) { print_error("Illegal IP 0.0.0.0"); } } else { /* no IP, we set it to 0.0.0.0 */ memset(ip, 0, 4); } /* we have collected MAC and IP, so we add an entry */ memcpy(((char *) workcopy->pool[nmacs].cmp) + 2, mac, 6); workcopy->pool[nmacs].ip = *(const uint32_t *) ip; nmacs++; /* re-allocate memory if needed */ if (*pc && nmacs >= workcopy->poolsize) { if (!(h = new_wormhash(nmacs * 2))) { print_memory(); } copy_wormhash(h, workcopy); free(workcopy); workcopy = h; } /* check if end of string was reached */ if (!*pc) { break; } /* now `pc' points to comma if we are here; */ /* increment this to the next char */ /* but first assert :-> */ if (*pc != ',') { print_error("Something went wrong; no comma...\n"); } pc++; /* again check if end of string was reached; */ /* we allow an ending comma */ if (!*pc) { break; } } if (!(result = new_wormhash(nmacs))) { print_memory(); } copy_wormhash(result, workcopy); free(workcopy); qsort(&result->pool, result->poolsize, sizeof(struct ebt_mac_wormhash_tuple), fcmp); index_table(result); return result; }
int main(int argc, char *argv[]) { FILE *fp, *fp2; char buf[100000][100]; /*命令 読み込み用バッファ */ char fpt[FPT_MAX_COUNT][20] = { 0 }; char ofname[1000] = "result"; int i = 0, j, k; //メモリ上の浮動小数点テーブルの位置 int fpmemoffset = 0; int result; bool doprintregs = false, doprintmem = false; program *answer; program2 *answer2; double t2, t1; int ll = 0; while ((result = getopt(argc, argv, "rmo:")) != -1) { switch (result) { /* 値をとらないオプション */ case 'r': /* getoptの返り値は見付けたオプションである. */ doprintregs = true; break; case 'm': doprintmem = true; break; case 'o': /* 値を取る引数の場合は外部変数optargにその値を格納する. */ strcpy(ofname, optarg); break; } } argc -= optind; argv += optind; /*assembler-file open and read */ fp = fopen(argv[0], "r"); if (fp == NULL) { printf("%sが開けませんaa\n", argv[0]); return 1; } if (argc > 1) { fp2 = fopen(argv[1], "r"); if (fp2 == NULL) { printf("%sが開けません\n", argv[1]); return 1; } for (i = 0; i < FPT_MAX_COUNT; ++i) { if (fgets(fpt[i], 20, fp2) == NULL) { /* 1行読み込み */ break; /* 末尾まで完了したか、エラー発生で終了 */ } } for (j = 0; j < i; ++j) { //エラーが起こっても関係ない //printf("%s\n", fpt[j]); memory[j + fpmemoffset].i = (int) strtoll(fpt[j], NULL, 16); } //print_memory(); } i = 0; while (1) { if (fgets(buf[i], 81, fp) == NULL) { /* 1行読み込み */ break; /* 末尾まで完了したか、エラー発生で終了 */ } i++; } out_fp = fopen(ofname, "w"); answer = parse_all(buf, i); answer2 = parse_all2(parse_all(buf, i)); //print_program(answer); t1 = gettimeofday_sec(); do_assemble2(answer, answer2); t2 = gettimeofday_sec(); printf("%lf\n", t2 - t1); printf("%lld\n", cnt); if (doprintregs) print_register(); if (doprintmem) print_memory(); fclose(fp); fclose(fp2); fclose(out_fp); return 0; }
/** * Acts as a withdraw process */ void withdraw(int request) { int semid = get_semid((key_t)SEMAPHORE_KEY); int shmid = get_shmid((key_t)SEMAPHORE_KEY); struct shared_variable_struct *shared_variables = shmat(shmid, 0, 0); // wait(mutex) printf("PID: %d - Someone is waiting on mutex to withdraw $%d.\n", getpid(), request); semaphore_wait(semid, SEMAPHORE_MUTEX); printf("PID: %d - Withdrawer:%d has passed mutex.\n", getpid(), request); // if (wcount = 0 and balance > withdraw) if (shared_variables->wcount == 0 && shared_variables->balance >= request) { // {balance = balance - withdraw; signal(mutex)} printf("PID: %d - A withdrawal of $%d was made!\n", getpid(), request); shared_variables->balance = shared_variables->balance - request; printf("PID: %d - Withdrawer:%d is signaling mutex.\n", getpid(), request); print_memory(shared_variables); semaphore_signal(semid, SEMAPHORE_MUTEX); } else { // wcount = wcount + 1; shared_variables->wcount = shared_variables->wcount + 1; // AddEndOfList(LIST, withdraw); printf("PID: %d - Withdrawer:%d is added to queue.\n", getpid(), request); insertLast(shared_variables->list, request); if (shared_variables->list->head == NULL) { printf("Totally null\n"); } // signal(mutex); printf("PID: %d - Withdrawer:%d is signaling mutex.\n", getpid(),request); semaphore_signal(semid, SEMAPHORE_MUTEX); print_memory(shared_variables); // wait(wlist); printf("PID: %d - Withdrawer is waiting to withdraw.\n", getpid()); semaphore_wait(semid, SEMAPHORE_WLIST); printf("PID: %d - Withdrawer is now ready to withdraw.\n", getpid()); // balance = balance - FirstRequestAmount(LIST); shared_variables->balance = shared_variables->balance - getFirstRequestAmount(shared_variables->list); //printf("%d\n", shared_variables->balance); // DeleteFirstRequest(LIST); removeFirst(shared_variables->list); // wcount = wcount - 1; shared_variables->wcount = shared_variables->wcount - 1; // if (wcount > 1 and (FirstRequestAmount(LIST)) < balance)) signal(wlist) if (shared_variables->wcount > 0 && getFirstRequestAmount(shared_variables->list) < shared_variables->balance) { printf("PID: %d - Withdrawer is signaling the next withdrawer.\n", getpid()); print_memory(shared_variables); semaphore_signal(semid, SEMAPHORE_WLIST); } // else signal(mutex)} else { printf("PID: %d - Withdrawer is signaling mutex.\n", getpid()); print_memory(shared_variables); semaphore_signal(semid, SEMAPHORE_MUTEX); } } if (shmdt(shared_variables) == -1) { perror("shmdt failed during a withdraw"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }