#define F_r 0x04 /* running only flag */
#define F_n 0x08 /* numeric output flag */
+#define PTABSIZE 128
+
int flags;
char *mapstat(char s)
int do_ps(void)
{
- int i, j, uid, pfd, ptsize;
+ int i, j, uid, pfd, ptsize, nodesize;
struct passwd *pwd;
+ struct p_tab_buffer *ppbuf;
struct p_tab *pp;
- static struct p_tab ptab[PTABSIZE];
+ static struct p_tab_buffer ptab[PTABSIZE];
static char name[10], uname[20];
uid = getuid();
return 1;
}
+ if (ioctl(pfd, 2, (char *) &nodesize) != 0) {
+ perror("ioctl");
+ close(pfd);
+ return 1;
+ }
+
+ if (nodesize > sizeof(struct p_tab_buffer)) {
+ fprintf(stderr, "kernel/user include mismatch.\n");
+ exit(1);
+ }
if (ioctl(pfd, 1, (char *) &ptsize) != 0) {
perror("ioctl");
close(pfd);
if (ptsize > PTABSIZE) ptsize = PTABSIZE;
+ /* FIXME: we don't need to buffer these first - it's silly */
for (i = 0; i < ptsize; ++i) {
- if (read(pfd, (char * ) &ptab[i], sizeof(struct p_tab)) !=
- sizeof(struct p_tab)) {
+ if (read(pfd, (char * ) &ptab[i], nodesize) !=
+ nodesize) {
fprintf(stderr, "ps: error reading from /dev/proc\n");
close(pfd);
return 1;
printf("USER\t PID\tSTAT\tWCHAN\tALARM\tCOMMAND\n");
}
- for (pp = ptab, i = 0; i < ptsize; ++i, ++pp) {
+ for (ppbuf = ptab, i = 0; i < ptsize; ++i, ++ppbuf) {
+ pp = &ppbuf->p_tab;
if (pp->p_status == 0)
continue;
/* Process table entry */
-typedef struct p_tab {
+struct p_tab {
/* WRS: UPDATE kernel.def IF YOU CHANGE THIS STRUCTURE */
uint8_t p_status; /* Process status: MUST BE FIRST MEMBER OF STRUCT */
uint8_t p_tty; /* Process' controlling tty minor # */
uint16_t p_pgrp; /* Process group */
uint8_t p_nice;
uint16_t p_top; /* Copy of u_top : FIXME: usize_t */
-#ifdef CONFIG_PROFIL
+};
+
+/* Followed by this structure if profiling supported */
+struct p_prof {
uint8_t p_profscale;
void * p_profbuf;
uint16_t p_profsize;
uint16_t p_profoff;
-#endif
};
-#ifndef PTABSIZE
-#define PTABSIZE 15 /* Process table size. */
-#endif
+/* Then this one if level 2 */
+struct p_level_2 {
+ uint16_t p_session;
+};
+
+/* The offsets of the prof and l2 are not guaranteed to be as per this
+ structure. Use this only for sizing */
+struct p_tab_buffer {
+ struct p_tab p_tab;
+ struct p_prof _prof;
+ struct p_level_2 _l2;
+};
#endif /* __PROC_H */