You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 lines
1.9 KiB

/* xsh_ps.c - xsh_ps */
#include <xinu.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------
* xsh_ps - shell command to print the process table
*------------------------------------------------------------------------
*/
shellcmd xsh_ps(int nargs, char *args[])
{
// uint32 * linkreg;
// asm volatile ("mov %0, lr" : : "r" (linkreg));
// kprintf("LINK REG: %x\n", linkreg);
struct procent *prptr; /* pointer to process */
int32 i; /* index into proctabl */
char *pstate[] = { /* names for process states */
"free ", "curr ", "ready", "recv ", "sleep", "susp ",
"wait ", "rtime"};
/* For argument '--help', emit help about the 'ps' command */
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
printf("Use: %s\n\n", args[0]);
printf("Description:\n");
printf("\tDisplays information about running processes\n");
printf("Options:\n");
printf("\t--help\t display this help and exit\n");
return 0;
}
/* Check for valid number of arguments */
if (nargs > 1) {
fprintf(stderr, "%s: too many arguments\n", args[0]);
fprintf(stderr, "Try '%s --help' for more information\n",
args[0]);
return 1;
}
/* Print header for items from the process table */
printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n",
"Pid", "Name", "State", "Prio", "Ppid", "Stack Base",
"Stack Ptr", "Stack Size");
printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n",
"---", "----------------", "-----", "----", "----",
"----------", "----------", "----------");
/* Output information for each process */
for (i = 0; i < NPROC; i++) {
prptr = &proctab[i];
if (prptr->prstate == PR_FREE) { /* skip unused slots */
continue;
}
printf("%3d %-16s %s %4d %4d 0x%08X 0x%08X %8d\n",
i, prptr->prname, pstate[(int)prptr->prstate],
prptr->prprio, prptr->prparent, prptr->prstkbase,
prptr->prstkptr, prptr->prstklen);
}
return 0;
}