SCCS-vsn: bin/ps/ps.c 4.3
+static char *sccsid = "@(#)ps.c 4.3 (Berkeley) %G%";
/*
* ps; VAX 4BSD version
*/
/*
* ps; VAX 4BSD version
*/
#include <sys/vm.h>
#include <sys/text.h>
#include <sys/stat.h>
#include <sys/vm.h>
#include <sys/text.h>
#include <sys/stat.h>
struct nlist nl[] = {
{ "_proc" },
struct nlist nl[] = {
{ "_proc" },
#define X_NSWAP 4
{ "_maxslp" },
#define X_MAXSLP 5
#define X_NSWAP 4
{ "_maxslp" },
#define X_MAXSLP 5
+ { "_ccpu" },
+#define X_CCPU 6
-/* F UID PID PPID CP PRI NI ADDR SZ RSS WCHAN S TT TIME */
+/* F UID PID PPID CP PRI NI ADDR SZ RSS WCHAN ST TT TIME */
struct lsav {
short l_ppid;
char l_cpu;
struct lsav {
short l_ppid;
char l_cpu;
-/* USER PID %CPU NICE SZ RSS TT F TIME */
+/* USER PID %CPU NI SZ RSS TT ST TIME */
-/* SSIZ PID TT S TIME */
+/* SSIZ PID TT ST TIME */
-/* F PID TT TIME RES SL MINFLT MAJFLT SIZE RSS SRS TSIZ TRS PF*/
+/* PID TT ST TIME RES SL MINFLT MAJFLT SIZE RSS SRS TSIZ TRS %CP*/
struct vsav {
u_int v_minflt, v_majflt;
size_t v_swrss, v_tsiz, v_txtrss, v_txtswrss;
short v_xccount;
struct vsav {
u_int v_minflt, v_majflt;
size_t v_swrss, v_tsiz, v_txtrss, v_txtswrss;
short v_xccount;
};
struct proc proc[8]; /* 8 = a few, for less syscalls */
};
struct proc proc[8]; /* 8 = a few, for less syscalls */
int aflg, cflg, eflg, gflg, kflg, lflg, sflg, uflg, vflg, xflg;
char *tptr;
char *gettty(), *getcmd(), *getname(), *savestr(), *alloc(), *state();
int aflg, cflg, eflg, gflg, kflg, lflg, sflg, uflg, vflg, xflg;
char *tptr;
char *gettty(), *getcmd(), *getname(), *savestr(), *alloc(), *state();
int pscomp();
int nswap, maxslp;
int pscomp();
int nswap, maxslp;
struct pte *Usrptma, *usrpt;
struct ttys {
struct pte *Usrptma, *usrpt;
struct ttys {
cantread("maxslp", kmemf);
exit(1);
}
cantread("maxslp", kmemf);
exit(1);
}
+ lseek(kmem, (long)nl[X_CCPU].n_value, 0);
+ if (read(kmem, &ccpu, sizeof (ccpu)) != sizeof (ccpu)) {
+ cantread("ccpu", kmemf);
+ exit(1);
+ }
if (vflg) {
text = (struct text *)alloc(NTEXT * sizeof (struct text));
if (text == 0) {
if (vflg) {
text = (struct text *)alloc(NTEXT * sizeof (struct text));
if (text == 0) {
sp->sun.vp = vp = (struct vsav *)alloc(sizeof (struct vsav));
#define e(a,b) vp->a = mproc->b
if (ap->a_stat != SZOMB) {
sp->sun.vp = vp = (struct vsav *)alloc(sizeof (struct vsav));
#define e(a,b) vp->a = mproc->b
if (ap->a_stat != SZOMB) {
- e(v_swrss, p_swrss); e(v_aveflt, p_aveflt);
vp->v_minflt = u.u_vm.vm_minflt;
vp->v_majflt = u.u_vm.vm_majflt;
if (mproc->p_textp) {
vp->v_minflt = u.u_vm.vm_minflt;
vp->v_majflt = u.u_vm.vm_majflt;
if (mproc->p_textp) {
vp->v_xccount = xp->x_ccount;
}
}
vp->v_xccount = xp->x_ccount;
}
}
#undef e
} else if (uflg)
#undef e
} else if (uflg)
- sp->sun.u_pctcpu = 0.0;
+ sp->sun.u_pctcpu = pcpu();
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;
+double
+pcpu()
+{
+
+ if (mproc->p_time == 0 || (mproc->p_flag&SLOAD) == 0)
+ return (0.0);
+ return (100.0 * mproc->p_pctcpu / (1.0 - exp(mproc->p_time * log(ccpu))));
+}
+
getu()
{
struct pte *pteaddr, apte, arguutl[UPAGES+CLSIZE];
getu()
{
struct pte *pteaddr, apte, arguutl[UPAGES+CLSIZE];
-" F UID PID PPID CP PRI NI ADDR SZ RSS WCHAN S TT TIME";
+" F UID PID PPID CP PRI NI ADDR SZ RSS WCHAN ST TT TIME";
lpr(sp)
struct savcom *sp;
{
lpr(sp)
struct savcom *sp;
{
-"USER PID %CPU NICE SZ RSS TT F TIME";
+"USER PID %CPU NI SZ RSS TT ST TIME";
upr(sp)
struct savcom *sp;
{
register struct asav *ap = sp->ap;
upr(sp)
struct savcom *sp;
{
register struct asav *ap = sp->ap;
- printf("%-8.8s %5u%5.1f%5d%4d%5d",
+ printf("%-8.8s %5u%5.1f%3d%5d%5d",
getname(ap->a_uid), ap->a_pid, sp->sun.u_pctcpu, ap->a_nice-NZERO,
ap->a_size/2, ap->a_rss/2);
putchar(' ');
getname(ap->a_uid), ap->a_pid, sp->sun.u_pctcpu, ap->a_nice-NZERO,
ap->a_size/2, ap->a_rss/2);
putchar(' ');
-" PID TT S TIME RES SL MINFLT MAJFLT SIZE RSS SRS TSIZ TRS PF";
+" PID TT ST TIME RES SL MINFLT MAJFLT SIZE RSS SRS TSIZ TRS %CP";
vpr(sp)
struct savcom *sp;
{
vpr(sp)
struct savcom *sp;
{
ptty(ap->a_tty);
printf(" %4s", state(ap));
ptime(ap);
ptty(ap->a_tty);
printf(" %4s", state(ap));
ptime(ap);
- printf("%4d%3d%7d%7d%5d%5d%5d%5d%4d%3d",
+ printf("%4d%3d%7d%7d%5d%5d%5d%5d%4d%4d",
ap->a_time, ap->a_slptime, vp->v_minflt, vp->v_majflt,
ap->a_size/2, ap->a_rss/2, vp->v_swrss/2,
ap->a_time, ap->a_slptime, vp->v_minflt, vp->v_majflt,
ap->a_size/2, ap->a_rss/2, vp->v_swrss/2,
- vp->v_tsiz/2, vp->v_txtrss/2, vp->v_aveflt);
+ vp->v_tsiz/2, vp->v_txtrss/2, vp->v_pctcpu);
spr(sp)
struct savcom *sp;
{
spr(sp)
struct savcom *sp;
{
+ if (uflg)
+ return (s2->sun.u_pctcpu > s1->sun.u_pctcpu ? 1 : -1);
if (vflg)
return (vsize(s2) - vsize(s1));
i = s1->ap->a_ttyd - s2->ap->a_ttyd;
if (vflg)
return (vsize(s2) - vsize(s1));
i = s1->ap->a_ttyd - s2->ap->a_ttyd;