SCCS-vsn: usr.bin/w/w.c 4.3
SCCS-vsn: bin/ps/ps.c 4.8
-static char *sccsid = "@(#)ps.c 4.7 (Berkeley) %G%";
+static char *sccsid = "@(#)ps.c 4.8 (Berkeley) %G%";
/*
* ps; VAX 4BSD version
*/
/*
* ps; VAX 4BSD version
*/
#define X_CCPU 6
{ "_ecmx" },
#define X_ECMX 7
#define X_CCPU 6
{ "_ecmx" },
#define X_ECMX 7
+ { "_nproc" },
+#define X_NPROC 8
+ { "_ntext" },
+#define X_NTEXT 9
+ { "_hz" },
+#define X_HZ 10
int s_ssiz;
} sun;
struct asav *ap;
int s_ssiz;
} sun;
struct asav *ap;
struct asav {
char *a_cmdp;
struct asav {
char *a_cmdp;
double pcpu(), pmem();
int pscomp();
int nswap, maxslp;
double pcpu(), pmem();
int pscomp();
int nswap, maxslp;
double ccpu;
int ecmx;
struct pte *Usrptma, *usrpt;
double ccpu;
int ecmx;
struct pte *Usrptma, *usrpt;
struct ttys {
char name[DIRSIZ+1];
struct ttys {
char name[DIRSIZ+1];
struct ttys *cand;
} *allttys, *cand[16];
struct ttys *cand;
} *allttys, *cand[16];
-struct savcom savcom[NPROC];
getdev();
uid = getuid();
printhdr();
getdev();
uid = getuid();
printhdr();
- procp = nl[X_PROC].n_value;
- for (i=0; i<NPROC; i += 8) {
+ procp = getw(nl[X_PROC].n_value);
+ nproc = getw(nl[X_NPROC].n_value);
+ hz = getw(nl[X_HZ].n_value);
+ savcom = (struct savcom *)calloc(nproc, sizeof (*savcom));
+ for (i=0; i<nproc; i += 8) {
lseek(kmem, (char *)procp, 0);
lseek(kmem, (char *)procp, 0);
if (j > 8)
j = 8;
j *= sizeof (struct proc);
if (j > 8)
j = 8;
j *= sizeof (struct proc);
+getw(loc)
+ off_t loc;
+{
+ long word;
+
+ lseek(kmem, loc, 0);
+ if (read(kmem, &word, sizeof (word)) != sizeof (word))
+ printf("error reading kmem at %x\n", loc);
+ return (word);
+}
+
openfiles(argc, argv)
char **argv;
{
openfiles(argc, argv)
char **argv;
{
exit(1);
}
if (uflg || vflg) {
exit(1);
}
if (uflg || vflg) {
- text = (struct text *)alloc(NTEXT * sizeof (struct text));
+ ntext = getw(nl[X_NTEXT].n_value);
+ text = (struct text *)alloc(ntext * sizeof (struct text));
if (text == 0) {
fprintf(stderr, "no room for text table\n");
exit(1);
}
if (text == 0) {
fprintf(stderr, "no room for text table\n");
exit(1);
}
- lseek(kmem, (long)nl[X_TEXT].n_value, 0);
- if (read(kmem, (char *)text, NTEXT * sizeof (struct text))
- != NTEXT * sizeof (struct text)) {
+ atext = (struct text *)getw(nl[X_TEXT].n_value);
+ lseek(kmem, (int)atext, 0);
+ if (read(kmem, (char *)text, ntext * sizeof (struct text))
+ != ntext * sizeof (struct text)) {
cantread("text table", kmemf);
exit(1);
}
cantread("text table", kmemf);
exit(1);
}
if (sumcpu)
ap->a_cpu += u.u_cvm.vm_utime + u.u_cvm.vm_stime;
if (mproc->p_textp && text) {
if (sumcpu)
ap->a_cpu += u.u_cvm.vm_utime + u.u_cvm.vm_stime;
if (mproc->p_textp && text) {
- xp = &text[mproc->p_textp -
- (struct text *)nl[X_TEXT].n_value];
+ xp = &text[mproc->p_textp - atext];
ap->a_tsiz = xp->x_size;
ap->a_txtrss = xp->x_rssize;
ap->a_xccount = xp->x_ccount;
}
}
#undef e
ap->a_tsiz = xp->x_size;
ap->a_txtrss = xp->x_rssize;
ap->a_xccount = xp->x_ccount;
}
}
#undef e
if (lflg) {
register struct lsav *lp;
if (lflg) {
register struct lsav *lp;
else if (sflg) {
if (ap->a_stat != SZOMB) {
for (cp = (char *)u.u_stack;
else if (sflg) {
if (ap->a_stat != SZOMB) {
for (cp = (char *)u.u_stack;
- cp < &user.upages[UPAGES][NBPG]; )
+ cp < &user.upages[UPAGES][0]; )
- sp->sun.s_ssiz = (&user.upages[UPAGES][NBPG] - cp);
+ sp->sun.s_ssiz = (&user.upages[UPAGES][0] - cp);
- printf("%3ld:%02ld", ap->a_cpu / HZ, ap->a_cpu % HZ);
+ printf("%3ld:%02ld", ap->a_cpu / hz, ap->a_cpu % hz);
-static char *sccsid = "@(#)w.c 4.2 (Berkeley) %G%";
+static char *sccsid = "@(#)w.c 4.3 (Berkeley) %G%";
/*
* w - print system status (who and what)
*
/*
* w - print system status (who and what)
*
#define ARGWIDTH 33 /* # chars left on 80 col crt for args */
#define ARGWIDTH 33 /* # chars left on 80 col crt for args */
short w_pid; /* proc.p_pid */
char w_flag; /* proc.p_flag */
short w_size; /* proc.p_size */
short w_pid; /* proc.p_pid */
char w_flag; /* proc.p_flag */
short w_size; /* proc.p_size */
dev_t w_tty; /* tty device of process */
char w_comm[15]; /* user.u_comm, null terminated */
char w_args[ARGWIDTH+1]; /* args if interesting process */
dev_t w_tty; /* tty device of process */
char w_comm[15]; /* user.u_comm, null terminated */
char w_args[ARGWIDTH+1]; /* args if interesting process */
struct nlist nl[] = {
{ "_proc" },
struct nlist nl[] = {
{ "_proc" },
#define X_AVENRUN 5
{ "_bootime" },
#define X_BOOTIME 6
#define X_AVENRUN 5
{ "_bootime" },
#define X_BOOTIME 6
+ { "_nproc" },
+#define X_NPROC 7
char doing[520]; /* process attached to terminal */
time_t proctime; /* cpu time of process in doing */
double avenrun[3];
char doing[520]; /* process attached to terminal */
time_t proctime; /* cpu time of process in doing */
double avenrun[3];
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
#define TTYEQ (tty == pr[i].w_tty)
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
#define TTYEQ (tty == pr[i].w_tty)
/*
* Locate proc table
*/
/*
* Locate proc table
*/
+ lseek(kmem, (long)nl[X_NPROC].n_value, 0);
+ read(kmem, &nproc, sizeof(nproc));
+ pr = (struct pr *)calloc(nproc, sizeof (struct pr));
- for (pn=0; pn<NPROC; pn++) {
- lseek(kmem, (long)(nl[X_PROC].n_value + pn*(sizeof mproc)), 0);
+ lseek(kmem, (long)nl[X_PROC].n_value, 0);
+ read(kmem, &aproc, sizeof(aproc));
+ for (pn=0; pn<nproc; pn++) {
+ lseek(kmem, (int)(aproc + pn), 0);
read(kmem, &mproc, sizeof mproc);
/* decide if it's an interesting process */
if (mproc.p_stat==0 || mproc.p_pgrp==0)
continue;
if (mproc.p_flag&SDETACH)
continue;
read(kmem, &mproc, sizeof mproc);
/* decide if it's an interesting process */
if (mproc.p_stat==0 || mproc.p_pgrp==0)
continue;
if (mproc.p_flag&SDETACH)
continue;
-
-#ifdef notdef
- /*
- * The following speeds up w on systems with lots of ttys
- * by ignoring inits and gettys, but loses on root login shells.
- * On Ernie it reduced user and system time by .3 seconds,
- * an insignificant amount. It is commented out since it
- * will lose when root logs in.
- */
- if (mproc.p_uid == 0 & mproc.p_ppid == 1)
- continue;
-#endif
-
/* find & read in the user structure */
if ((mproc.p_flag & SLOAD) == 0) {
/* not in memory - get from swap device */
/* find & read in the user structure */
if ((mproc.p_flag & SLOAD) == 0) {
/* not in memory - get from swap device */
{
int c, addr, nbad;
static int abuf[512/sizeof(int)];
{
int c, addr, nbad;
static int abuf[512/sizeof(int)];