Example #1
0
File: ps.c Project: erkinalp/FUZIX
void display_process(struct p_tab *pp, int i)
{
	int j;

	if (outflags & OF_F)
		fputs("0 ", stdout);
	if (outflags & OF_S) {
		putchar(mapstat(pp->p_status));
		putchar(' ');
	}
	if (outflags & OF_UID)
		printf("%5d ", pp->p_uid);
	if (outflags & OF_PID)
		printf("%5d ", pp->p_pid);
	if (outflags & OF_PPID)
		printf("%5d ", ptab[ppid_slot[i]].p_tab.p_pid);
	if (outflags & OF_C)
		fputs(" 0 ", stdout);
	if (outflags & OF_PRI)
		printf("%3d ", pp->p_priority);
	if (outflags & OF_NI)
		printf("%3d ", pp->p_nice);
	if (outflags & OF_ADDR)
		fputs("    - ", stdout);
	if (outflags & OF_SZ)
		fputs("    - ", stdout);
	if (outflags & OF_WCHAN) {
		if (pp->p_status > 2)
			printf("%5d ", (unsigned int)pp->p_wait);
		else
			fputs("    - ", stdout);
	}
	/* We need to sort out the whole kernel and user handling of
	   times in ptab verus udata here */
	if (outflags & OF_STIME)
		fputs("00:00 ", stdout);	/* FIXME */
	if (outflags & OF_TTY) {
		if (!pp->p_tty)
			fputs("     ? ", stdout);
		else
			printf("%6s ", ttyshortname(pp->p_tty));
	}
	if (outflags & OF_TIME)
		fputs("00:00:00 ", stdout);	/* FIXME */
	if (outflags & OF_CMD) {
		char name[9];
		strncpy(name, pp->p_name, 8);
		name[8] = '\0';

		for (j = 0; j < 8; ++j) {
			if (name[j] != 0)
				if (name[j] < ' ' || name[j] > 126)
					name[j] = '?';
		}
		fputs(name, stdout);
		if (pp->p_status == P_ZOMBIE)
			fputs(" <defunct>", stdout);
		putchar('\n');
	}
}
Example #2
0
File: ps.c Project: jameszhan/FUZIX
void display_process(struct p_tab *pp, int i)
{
	int j;

	if (outflags & OF_F)
		fputs("0 ", stdout);
	if (outflags & OF_S) {
		putchar(mapstat(pp->p_status));
		putchar(' ');
	}
	if (outflags & OF_UID)
		printf("%5d ", pp->p_uid);
	if (outflags & OF_PID)
		printf("%5d ", pp->p_pid);
	if (outflags & OF_PPID)
		printf("%5d ", ptab[ppid_slot[i]].p_tab.p_pid);
	if (outflags & OF_C)
		fputs(" 0 ", stdout);
	if (outflags & OF_PRI)
		printf("%3d ", pp->p_priority);
	if (outflags & OF_NI)
		printf("%3d ", pp->p_nice);
	if (outflags & OF_ADDR)
		fputs("    - ", stdout);
	if (outflags & OF_SZ)
		fputs("    - ", stdout);
	if (outflags & OF_WCHAN) {
		if (pp->p_status > 2)
			printf("%5d ", (unsigned int)pp->p_wait);
		else
			fputs("    - ", stdout);
	}
	/* We need to sort out the whole kernel and user handling of
	   times in ptab verus udata here */
	if (outflags & OF_STIME) {
		uint32_t t;
		t = time(NULL) - pp->p_stime;
		if ((t - pp->p_stime) > 86400)
			printf("%02day ", t / 86400);
		else {
			struct tm *tm;
			time_t x = pp->p_stime;
			tm = localtime(&x);
			printf("%02d:%02d ",
				tm->tm_hour, tm->tm_min);
		}
	}
				
	if (outflags & OF_TTY) {
		if (!pp->p_tty)
			fputs("     ? ", stdout);
		else
			printf("%6s ", ttyshortname(pp->p_tty));
	}
	if (outflags & OF_TIME) {
		/* cstime/cutime or ctime/utime ? */ 
		uint32_t c = pp->p_cstime + pp->p_cutime;
		uint8_t secs = c % 60;
		uint8_t mins;
		c -= secs;
		c /= 60;
		mins = c % 60;
		c -= mins;
		c /= 60;
		/* What to do if we exceed 99 hours ? */
		printf("%02d:%02d:%02d ",
			c, mins, secs);
	}
	if (outflags & OF_CMD) {
		char name[9];
		strncpy(name, pp->p_name, 8);
		name[8] = '\0';

		for (j = 0; j < 8; ++j) {
			if (name[j] != 0)
				if (name[j] < ' ' || name[j] > 126)
					name[j] = '?';
		}
		fputs(name, stdout);
		if (pp->p_status == P_ZOMBIE)
			fputs(" <defunct>", stdout);
		putchar('\n');
	}
}