kolibrios-gitea/programs/system/shell/cmd/cmd_ps.c
Rustem Gimadutdinov (rgimad) 68cf3e4293 SHELL 0.8.2
- big refactoring, now uses libc.obj
- added kfetch command

git-svn-id: svn://kolibrios.org@8827 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-06-12 21:34:41 +00:00

41 lines
804 B
C

int cmd_ps(char param[])
{
int i, n, sel;
char *buf1k;
unsigned PID;
short STATE;
buf1k = malloc(1024);
if (NULL == buf1k)
return FALSE;
sel = param && strlen(param) > 0;
printf (" PID NAME RAM KB\n\r", PID, buf1k+10);
for (i = 1;;i++) {
n = kol_process_info(i, buf1k);
memcpy(&PID, buf1k+30 ,sizeof(unsigned));
STATE = *(buf1k+50);
if (9 != STATE) {
if (!sel || 0 == strnicmp(param, buf1k+10, 10)) {
printf (" %7u %11s %d\n\r", PID, buf1k+10, (*(int*)(buf1k+26)+1)/1024);
if (sel) {
LAST_PID = PID;
int cpu_tck = kol_system_cpufreq() / 100;
printf (" CPU %d%% RAM %d\n\r", *(int*)buf1k / cpu_tck , *(int*)(buf1k+26)+1);
}
}
}
if (i == n)
break;
}
free(buf1k);
return TRUE;
}