Example #1
0
File: ps.c Project: erkinalp/FUZIX
int do_ps(void)
{
	int i, pfd, ptsize, nodesize;
	struct p_tab_buffer *ppbuf;
	struct p_tab *pp;

	uid = geteuid();
	pid = getpid();

	if ((pfd = open("/dev/proc", O_RDONLY)) < 0) {
		perror("ps");
		return 1;
	}

	if (ioctl(pfd, 2, (char *) &nodesize) != 0) {
		perror("ioctl");
		close(pfd);
		return 1;
	}

	if (nodesize > sizeof(struct p_tab_buffer)) {
		fprintf(stderr, "kernel/user include mismatch.\n");
		exit(1);
	}

	if (ioctl(pfd, 1, (char *) &ptsize) != 0) {
		perror("ioctl");
		close(pfd);
		return 1;
	}

	if (ptsize > PTABSIZE)
		ptsize = PTABSIZE;

	for (i = 0; i < ptsize; ++i) {
		if (read(pfd, (char *) &ptab[i], nodesize) != nodesize) {
			fprintf(stderr, "ps: error reading from /dev/proc\n");
			close(pfd);
			return 1;
		}
		ppid_slot[i] = ptab[i].p_tab.p_pptr - ptab[0].p_tab.p_pptr;
		/* Learn our tty internal reference as we go */
		if (ptab[i].p_tab.p_status && ptab[i].p_tab.p_pid == pid)
			tty = ptab[i].p_tab.p_tty;
	}
	close(pfd);

	print_header();

	for (ppbuf = ptab, i = 0; i < ptsize; ++i, ++ppbuf) {
		pp = &ppbuf->p_tab;

		if (!show_process(pp))
			continue;

		display_process(pp, i);
	}
	return 0;
}
Example #2
0
int main()
{
	printf("Content-type:text/html\r\n\r\n");
	printf("<html><head><title>CPUINFO</title>\
                <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>");

	printf("<body><table style='border:2px; border-color:red'; >");
	show_process();
	printf("</table></body></html>\n");
	return 0;
}