예제 #1
0
파일: top.c 프로젝트: AgamAgarwal/minix
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 codegen_prog(FILE *fp, Program prog) {
    Procs sorted_procs = sort_procs(prog->procs);
    printf("call proc_main\n");
    printf("halt\n");
    printf("\n");
    print_procs(sorted_procs);
}
예제 #3
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;
}
/* 
    Print all procs
*/
void print_procs(Procs procs) {
    Proc first = procs->first;
    Procs rest = procs->rest;
    
    // Print all procs
    if (first) {
        print_proc(first);
        printf("\n");

    }
    if (rest) {
        print_procs(rest);
    }
}
예제 #5
0
void start_text_dump(void)
{
	struct timeval now;
	struct tm *tm;
	signal(SIGINT, signal_func);
	signal(SIGTERM, signal_func);

	while (!done) {
		gettimeofday(&now, NULL);
		printf("=============== %s", asctime(localtime(&now.tv_sec)));
		update_list();
		print_global_list();
		print_procs();
		if (done)
			break;
		sleep(10);
	}
}
예제 #6
0
/**
 * Executes the issued command
 */
void console_exec(char *buf) {
    if(strncmp(buf, "cd", 2) == 0) {
        console_cd(dir, buf);
    } else if(strncmp(buf, "start", 5) == 0) {
        console_start(dir, buf);
    } else if(strncmp(buf, "read", 4) == 0) {
        console_read(dir, buf);
    } else if(strncmp(buf, "write", 5) == 0) {
        console_write(dir, buf);
    } else if(strncmp(buf, "touch", 5) == 0) {
        console_touch(dir, buf);
    } else if(strncmp(buf, "delete", 6) == 0) {
        console_delete(dir, buf);
    } else if(strcmp(buf, "hoho") == 0) {
        printk("hoho\n");
    } else if(strcmp(buf, "help") == 0) {
        printk("Help:\nhoho - prints hoho\nhelp - shows help\nmeminfo - prints RAM info\ncpuinfo - shows CPU info\nls - shows filesystem devices\nread - reads a file\nstart - starts a program\nclear - clears the screen\nhalt - shuts down\nreboot - reboots the pc\n");
    } else if(strcmp(buf, "meminfo") == 0) {
        print_meminfo();
    } else if(strcmp(buf, "cpuinfo") == 0) {
        printk("%s\n", get_cpu_vendor(0));
    } else if(strcmp(buf, "ls") == 0) {
        if(dir[0] == 0) {
            vfs_ls();
        } else {
            vfs_ls_dir(dir);
        }
    } else if(strcmp(buf, "clear") == 0) {
        clear();
    } else if(strcmp(buf, "proc") == 0) {
        print_procs();
    } else if(strcmp(buf, "halt") == 0) {
        printk("Shutting down\n");
        halt();
        while(1);
    } else if(strcmp(buf, "reboot") == 0) {
        printk("Rebooting\n");
        reboot();
    } else {
        printk("Command not found\n");
    }
}
예제 #7
0
파일: main.cpp 프로젝트: maxrake/CppCourse
int main(int argc, char** argv, char** envp)
{
    pids.resize(100);
    auto size = get_pidlist(pids);

    while (pids.size()/sizeof(int) <= size)
    {
        pids.resize(pids.size() * 2);
        size = get_pidlist(pids);
    }

    pids.resize(size / sizeof(int));

    for (auto x : pids)
    {
        std::string name = get_proc_name(x);
        if( name != "Unable to open process. Skipping...")
            procList[x] = get_proc_name(x);
    }

    print_procs(procList);

	return 0;
}
예제 #8
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));
}
예제 #9
0
int top_main(int argc, char *argv[]) {
    int i;

    num_used_procs = num_free_procs = 0;

    max_procs = 0;
    delay = 3;
    iterations = -1;
    proc_cmp = &proc_cpu_cmp;
    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-m")) {
            if (i + 1 >= argc) {
                fprintf(stderr, "Option -m expects an argument.\n");
                usage(argv[0]);
                exit(EXIT_FAILURE);
            }
            max_procs = atoi(argv[++i]);
            continue;
        }
        if (!strcmp(argv[i], "-n")) {
            if (i + 1 >= argc) {
                fprintf(stderr, "Option -n expects an argument.\n");
                usage(argv[0]);
                exit(EXIT_FAILURE);
            }
            iterations = atoi(argv[++i]);
            continue;
        }
        if (!strcmp(argv[i], "-d")) {
            if (i + 1 >= argc) {
                fprintf(stderr, "Option -d expects an argument.\n");
                usage(argv[0]);
                exit(EXIT_FAILURE);
            }
            delay = atoi(argv[++i]);
            continue;
        }
        if (!strcmp(argv[i], "-s")) {
            if (i + 1 >= argc) {
                fprintf(stderr, "Option -s expects an argument.\n");
                usage(argv[0]);
                exit(EXIT_FAILURE);
            }
            ++i;
            if (!strcmp(argv[i], "cpu")) { proc_cmp = &proc_cpu_cmp; continue; }
            if (!strcmp(argv[i], "vss")) { proc_cmp = &proc_vss_cmp; continue; }
            if (!strcmp(argv[i], "rss")) { proc_cmp = &proc_rss_cmp; continue; }
            if (!strcmp(argv[i], "thr")) { proc_cmp = &proc_thr_cmp; continue; }
            fprintf(stderr, "Invalid argument \"%s\" for option -s.\n", argv[i]);
            exit(EXIT_FAILURE);
        }
        if (!strcmp(argv[i], "-t")) { threads = 1; continue; }
        if (!strcmp(argv[i], "-h")) {
            usage(argv[0]);
            exit(EXIT_SUCCESS);
        }
        fprintf(stderr, "Invalid argument \"%s\".\n", argv[i]);
        usage(argv[0]);
        exit(EXIT_FAILURE);
    }

    if (threads && proc_cmp == &proc_thr_cmp) {
        fprintf(stderr, "Sorting by threads per thread makes no sense!\n");
        exit(EXIT_FAILURE);
    }

    free_procs = NULL;

    num_new_procs = num_old_procs = 0;
    new_procs = old_procs = NULL;

    read_procs();
    while ((iterations == -1) || (iterations-- > 0)) {
        old_procs = new_procs;
        num_old_procs = num_new_procs;
        memcpy(&old_cpu, &new_cpu, sizeof(old_cpu));
        sleep(delay);
        read_procs();
        print_procs();
        free_old_procs();
    }

    return 0;
}