00001
00007
00008
00009 #include <kernel.h>
00010 #include <proc.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <stdlib.h>
00014
00023 command xsh_ps(ushort stdin, ushort stdout, ushort stderr,
00024 ushort nargs, char *args[])
00025 {
00026 pcb *ppcb;
00027 uchar i;
00028
00029
00030 char *pstnams[] =
00031 { "curr ", "free ", "ready", "recv ",
00032 "sleep", "susp ", "wait ", "rtim " };
00033
00034
00035 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00036 {
00037 fprintf(stdout, "Usage: ps\n");
00038 fprintf(stdout, "Displays a table of running processes.\n");
00039 fprintf(stdout, "\t--help\t display this help and exit\n");
00040
00041 return OK;
00042 }
00043
00044
00045 if (nargs > 1)
00046 {
00047 fprintf(stderr, "ps: too many arguments\n");
00048 fprintf(stderr, "Try 'ps --help' for more information\n");
00049 return SYSERR;
00050 }
00051
00052
00053 fprintf(stdout,
00054 "PID NAME STATE PRIO PPID STACK BASE STACK PTR STACK LEN \n");
00055 fprintf(stdout,
00056 "--- ------------ ----- ---- ---- ---------- ---------- ----------\n");
00057
00058
00059 for ( i = 0; i < NPROC; i++ )
00060 {
00061 ppcb = &proctab[i];
00062 if (ppcb->state == PRFREE) { continue; }
00063
00064 fprintf(stdout, "%3d %-12s %s %4d %4d 0x%08X 0x%08X %10d\n",
00065 i, ppcb->name, pstnams[(int)ppcb->state-1],
00066 ppcb->prio, ppcb->parent, ppcb->stkbase,
00067 ppcb->stkptr, ppcb->stklen);
00068 }
00069
00070 return OK;
00071 }