XINU
Functions
xsh_ps.c File Reference
#include <xinu.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for xsh_ps.c:

Go to the source code of this file.

Functions

shellcmd xsh_ps (int nargs, char *args[])
 

Function Documentation

◆ xsh_ps()

shellcmd xsh_ps ( int  nargs,
char *  args[] 
)

Definition at line 11 of file xsh_ps.c.

References fprintf(), NPROC, PR_FREE, printf(), procent::prname, proctab, procent::prparent, procent::prprio, procent::prstate, procent::prstkbase, procent::prstklen, procent::prstkptr, stderr, and strncmp().

12 {
13  struct procent *prptr; /* pointer to process */
14  int32 i; /* index into proctabl */
15  char *pstate[] = { /* names for process states */
16  "free ", "curr ", "ready", "recv ", "sleep", "susp ",
17  "wait ", "rtime"};
18 
19  /* For argument '--help', emit help about the 'ps' command */
20 
21  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
22  printf("Use: %s\n\n", args[0]);
23  printf("Description:\n");
24  printf("\tDisplays information about running processes\n");
25  printf("Options:\n");
26  printf("\t--help\t display this help and exit\n");
27  return 0;
28  }
29 
30  /* Check for valid number of arguments */
31 
32  if (nargs > 1) {
33  fprintf(stderr, "%s: too many arguments\n", args[0]);
34  fprintf(stderr, "Try '%s --help' for more information\n",
35  args[0]);
36  return 1;
37  }
38 
39  /* Print header for items from the process table */
40 
41  printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n",
42  "Pid", "Name", "State", "Prio", "Ppid", "Stack Base",
43  "Stack Ptr", "Stack Size");
44 
45  printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n",
46  "---", "----------------", "-----", "----", "----",
47  "----------", "----------", "----------");
48 
49  /* Output information for each process */
50 
51  for (i = 0; i < NPROC; i++) {
52  prptr = &proctab[i];
53  if (prptr->prstate == PR_FREE) { /* skip unused slots */
54  continue;
55  }
56  printf("%3d %-16s %s %4d %4d 0x%08X 0x%08X %8d\n",
57  i, prptr->prname, pstate[(int)prptr->prstate],
58  prptr->prprio, prptr->prparent, prptr->prstkbase,
59  prptr->prstkptr, prptr->prstklen);
60  }
61  return 0;
62 }
pid32 prparent
このプロセスを作成したプロセスID(親プロセスID)。
Definition: process.h:102
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
uint32 prstklen
Bytesで表されたスタックの長さ(最大値。Byte)。
Definition: process.h:96
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
char prname[PNMLEN]
プロセス名。
Definition: process.h:98
#define NPROC
Definition: conf.h:79
char * prstkbase
ランタイムスタックの基点(メモリ領域で最上位のアドレス)。
Definition: process.h:94
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
#define PR_FREE
プロセステーブルエントリが使用されていない状態。
Definition: process.h:35
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
char * prstkptr
保存されたスタックポインタ。
Definition: process.h:92
Here is the call graph for this function: