pstat.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,614 行 · 第 1/3 页

C
1,614
字号
		putf(gp->g_flag&GLWAIT, 'Z');		printf("%4d", gp->g_count&0377);		printf("%4d,%3d", major(gp->g_dev), minor(gp->g_dev));		printf("%4d", gp->g_shlockc&0377);		printf("%4d", gp->g_exlockc&0377);		printf("%6d", gp->g_number);		printf("%6x", gp->g_mode & 0xffff);		printf("%4d", gp->g_nlink);		printf("%4d", gp->g_uid);		if ((gp->g_mode&GFMT)==GFBLK || (gp->g_mode&GFMT)==GFCHR)			printf("%6d,%3d", major(gp->g_rdev), minor(gp->g_rdev));		else			printf("%10ld", gp->g_size);		printf("\n");	}	free(xgnode);}getw(loc)	unsigned long loc;{	int word;	klseek(fc, loc, 0);	read(fc, &word, sizeof (word));	return (word);}putf(v, n){	if (v)		printf("%c", n);	else		printf(" ");}dotext(){	register struct text *xp;	register int ntext;	struct text *xtext;	register struct text *atext;	register int nrecl=0,nactive=0;	ntext = getw(nl[SNTEXT].n_value);	if((xtext = (struct text *)calloc(ntext, sizeof (struct text))) == 	(struct text *) NULL) {		perror("calloc: dotext");		exit(1);	}	klseek(fc, (int)(atext = (struct text *)getw(nl[STEXT].n_value)), 0);	read(fc, xtext, ntext * sizeof (struct text));	for (xp = xtext; xp < &xtext[ntext]; xp++) {		if (xp->x_gptr!=NULL && (xp->x_flag & XFREE))			nrecl++;		if ((xp->x_flag & XFREE) == 0)			nactive++;	}	printf("%4d/%4d/%4d\tactive/reclaimable/total texts\n",					nactive, nrecl, ntext);	if (totflg) return;	printf("   LOC   FLAGS        DADDR    CADDR    RSS SIZE   GPTR   CNT CCNT LCNT POIP\n");	for (xp = xtext; xp < &xtext[ntext]; xp++) {		if (xp->x_gptr == NULL)			continue;		printf("%8.1x", atext + (xp - xtext));		printf(" ");		putf(xp->x_flag&XPAGI, 'P');		putf(xp->x_flag&XTRC, 'T');		putf(xp->x_flag&XWRIT, 'W');		putf(xp->x_flag&XLOAD, 'L');		putf(xp->x_flag&XLOCK, 'K');		putf(xp->x_flag&XFREE, 'F');		putf(xp->x_flag&XWANT, 'w');		putf(xp->x_flag&XNOSW, 'l');		putf(xp->x_flag&XBAD, 'B');		putf(xp->x_flag&XREMOTE, 'R');		printf("%9x", xp->x_dmap);		printf("%9.1x", xp->x_caddr);		printf("%5d", xp->x_rssize);		printf("%5d", xp->x_size);		printf("%9.1x", xp->x_gptr);		printf("%4d", xp->x_count&0377);		printf("%4d", xp->x_ccount);		printf("%5d", xp->x_lcount);		printf("%5d", xp->x_poip);		printf("\n");	}	free(xtext);}doproc(){	struct proc *xproc;	register struct proc *aproc;	register int nproc;	register struct proc *pp;	register int np;	struct timeval curr_time;	struct pte apte;	register int ten_msec;	int *bit_map;	int i;	nproc = getw(nl[SNPROC].n_value);	if((xproc = (struct proc *)calloc(nproc, sizeof (struct proc))) == 	(struct proc *) NULL) {		perror("calloc: doproc");		exit(1);	}	klseek(fc, (int)(aproc = (struct proc *)getw(nl[SPROC].n_value)), 0);	read(fc, xproc, nproc * sizeof (struct proc));	bit_map = (int *) calloc((nproc+31)/32,sizeof (int));	klseek(fc, (int) nl[SPROC_BITMAP].n_value, 0);	read(fc, bit_map, ((nproc+31)/32) * sizeof (int));	np = 0;	for(i=0; i< nproc; i++)		if (bit_map[(i/32)] & (1<<(i%32)))			np++;	if (totflg) {		printf("%4d/%4d\tprocesses\n", np, nproc);		return;	}	gettimeofday(&curr_time, 0);	printf("%d/%d processes\n", np, nproc);	printf("   LOC    S    F POIP PRI      SIG  UID SLP TIM  CPU  NI   PGRP    PID   PPID    ADDR   RSS SRSS SIZE    WCHAN     LINK   TEXTP CLKT  TTYP LOCK DMAP    SMAP\n");	for (pp=xproc, i=0; pp<&xproc[nproc]; pp++,i++) {		if (((bit_map[(i/32)] & (1<<(i%32))) == 0)			&& allflg ==0) continue;		printf("%8x", aproc + (pp - xproc));		printf(" %2d", pp->p_stat);		printf(" %4x", (pp->p_sched | pp->p_select | pp->p_vm |				pp->p_trace |				pp->p_type |pp->p_file) & 0xffff);		printf(" %4d", pp->p_poip);		printf(" %3d", pp->p_pri);		printf(" %8x", pp->p_sig);		printf(" %4d", pp->p_uid);		printf(" %3d", pp->p_slptime);		printf(" %3d", pp->p_time);		printf(" %4d", pp->p_cpu&0377);		printf(" %3d", pp->p_nice);		printf(" %6d", pp->p_pgrp);		printf(" %6d", pp->p_pid);		printf(" %6d", pp->p_ppid);		klseek(fc, (long)(Usrptma+btokmx(pp->p_addr)), 0);		read(fc, &apte, sizeof(apte));		printf(" %8x", apte.pg_pfnum);	/* print page of page table */		printf(" %4x", pp->p_rssize);		printf(" %4x", pp->p_swrss);		printf(" %5x", pp->p_dsize+pp->p_ssize);		printf(" %8x", clear(pp->p_wchan));		printf(" %7x", clear(pp->p_link));		printf(" %7x", clear(pp->p_textp));		if ((pp->p_realtimer.it_value.tv_sec == 0) && 		    (pp->p_realtimer.it_value.tv_usec == 0))			printf("     ");		else if (timercmp(&pp->p_realtimer.it_value,&curr_time,<))			printf("  %3d",-1);		else {			ten_msec = (pp->p_realtimer.it_value.tv_sec - 				curr_time.tv_sec) * 100;			ten_msec += ((pp->p_realtimer.it_value.tv_usec - 				curr_time.tv_usec) / 10000);			if (ten_msec > 1000000) 				printf(" %3dM",ten_msec / 1000000);			else if (ten_msec > 1000) 				printf(" %3dK",ten_msec / 1000);			else				printf("  %3d",ten_msec);		}		printf(" %5x", clear(pp->p_ttyp));		printf(" %8x", pp->p_hlock);		printf(" %8x", pp->p_dmap);		printf(" %8x", pp->p_smap);		printf("\n");	}}#ifdef vaxdovec(){	struct proc *xproc;	register struct proc *aproc;	register int nproc;	register struct proc *pp;	register int nvp;	struct vpcontext	vpc;	int i;	int nocxt;	nproc = getw(nl[SNPROC].n_value);	if((xproc = (struct proc *)calloc(nproc, sizeof (struct proc))) == 	(struct proc *) NULL) {		perror("calloc: doproc");		exit(1);	}	klseek(fc, (int)(aproc = (struct proc *)getw(nl[SPROC].n_value)), 0);	read(fc, xproc, nproc * sizeof (struct proc));	nvp = 0;	for(i=0; i< nproc; i++) {		if(xproc[i].p_vpcontext) {			nvp++;		}	}	printf("%d/%d vector processes\n", nvp, nproc);	printf("   LOC     PGRP    PID   PPID   VST   VERRS  REFS CHPCXT EXPCXT\n");	for (pp=xproc, i=0; pp<&xproc[nproc]; pp++,i++) {		if(pp->p_vpcontext) {			klseek(fc, pp->p_vpcontext, 0);			read(fc, &vpc, sizeof(struct vpcontext));			printf("%8x %6d %6d %6d ", aproc + (pp - xproc),				pp->p_pgrp, pp->p_pid, pp->p_ppid);			nocxt = 0;			switch(vpc.vpc_state) {				case VPC_WAIT:						printf(" WAIT ");						break;				case VPC_LOAD:						printf(" LOAD ");						break;				case VPC_SAVED:						printf("SAVED ");						break;				case VPC_LIMBO:						printf("LIMBO ");						break;				default:						printf("  ??? ");						nocxt = 1;					break;			}			if(!nocxt) {			    printf("%6d %6d %6d %6d\n", vpc.vpc_error,				vpc.vpc_refuse, vpc.vpc_cheap, vpc.vpc_expen);			}			else {			    printf("\n");			}		}			}}#endif /* vax */dotty(){	struct tty dz_tty[256];	int ndz;	register struct tty *tp;	register char *mesg;	register struct ttytype *ttype;	struct lock_t dmb_lock[16], cfree_lock;	int i;	if (ttylock == 0) {		mesg = " # RAW CAN OUT    MODE    ADDR   DEL COL  STATE         PGRP DISC\n";		printf(mesg);	}	else {		smp_title++;	}	klseek(fc, (long)nl[SKL].n_value, 0);	read(fc, dz_tty, sizeof(dz_tty[0]));	/*	 * The console will be on ss line 0 or 3 if the	 * CPU is a VAXstar or MICROVAX 1800. Don't print	 * the console line if this is the case.	 */	tp = dz_tty;	if((tp->t_state&TS_ISOPEN) || (((long)nl[SSS].n_type == 0) &&	   ((long)nl[SDC].n_type == 0)) && ((long)nl[SMDC].n_type == 0)) {		printf("\n1 console\n"); /* console */		ttyprt(&dz_tty[0], 0);	}	for (ttype=ttytypes; *ttype->name != '\0'; ttype++) {		if (nl[ttype->nttys].n_type == 0)			continue;		klseek(fc, (long)nl[ttype->nttys].n_value, 0);		read(fc, &ndz, sizeof(ndz));		/*		 * Display DMB lock status for the per-board lock.		 */		if ((ttype->ttybase == SDMB) && (nl[SDMB].n_type != 0)) {			klseek(fc, (long)nl[SNLKDMB].n_value, 0);			read(fc, dmb_lock, ((sizeof (dmb_lock)) * ndz/16));			for (i = 0; i < ndz/16; i++) {				printf("\n dmb board %d lock statistics\n",i);				smp_stat(-1,dmb_lock[i].l_spin,dmb_lock[i].l_lost,					dmb_lock[i].l_won);				smp_title++;			}		}		printf("\n%d %s lines\n", ndz, ttype->name);		klseek(fc, (long)nl[ttype->ttybase].n_value, 0);		read(fc, dz_tty, ndz * sizeof (struct tty));		for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)			ttyprt(tp, tp - dz_tty);		if (ttylock)			smp_title++;	}}ttyprt(atp, line)struct tty *atp;{	register struct tty *tp;	tp = atp;    if (ttylock == 0) {	printf("%2d", line);	printf("%4d ", tp->t_outq.c_cc);	printf("%8.1x", tp->t_flags);	printf(" %8.1x", tp->t_addr);	printf("%3d", tp->t_delct);	printf("%4d ", tp->t_col);	putf(tp->t_state&TS_TIMEOUT, 'T');	putf(tp->t_state&TS_WOPEN, 'W');	putf(tp->t_state&TS_ISOPEN, 'O');	putf(tp->t_state&TS_CARR_ON, 'C');	putf(tp->t_state&TS_BUSY, 'B');	putf(tp->t_state&TS_ASLEEP, 'A');	putf(tp->t_state&TS_XCLUDE, 'X');	putf(tp->t_cflag&HUPCL, 'H');	putf(tp->t_state&TS_TTSTOP, 'S');	putf(tp->t_state&TS_INUSE, 'I');	putf(tp->t_state&TS_ONDELAY, 'D');	putf(tp->t_state&TS_IGNCAR, 'G');	putf(tp->t_state&TS_NBIO, 'N');	putf(tp->t_state&TS_ASYNC, 'Z');	putf(tp->t_state&TS_CLOSING, 'L');	putf(tp->t_state&TS_OABORT, 'Q');	printf("%6d", tp->t_pgrp);	switch (tp->t_line) {	case NTTYDISC:		printf(" ntty");		break;	case NETLDISC:		printf(" net");		break;	case HCLDISC:		printf(" uucp");		break;	case TERMIODISC:		printf(" termio");		break;	case SLPDISC:		printf(" slp");		break;	}	printf("\n");    }    /*     * Display lock stats for SMP terminal drivers.     */    else {	if (tp->t_smp) {		smp_stat(line,tp->t_lk_tty.l_spin,tp->t_lk_tty.l_lost,tp->t_lk_tty.l_won);  	}    }}dousr(){	union {		struct user user;		char upages[UPAGES+CLSIZE][NBPG];	} un_user;#define U un_user.user	register int i, j, *ip, ncl;	register struct nameidata *nd = &U.u_nd;	struct pte arguutl[UPAGES+CLSIZE];	struct ucred ucred;	int *ofile_of,fp;	char *pofile_of,fflg;	/* ubase is the 1st page of the user page table */	/* We will use this to seek to then back up UPAGES+CLSIZE pte's */	/* and read in the pte's to get all the pages of the u area */	klseek(fm,(long)ctob(ubase)-(UPAGES+CLSIZE)*sizeof(struct pte),0);	if (read(fm, (char *)arguutl, sizeof(arguutl)) != sizeof(arguutl)) {		printf("pstat: cant read page table for u at addr %x\n",ubase);		return;	}	/* Now figure out the number of clicks to read */	ncl = (sizeof(struct user) + NBPG*CLSIZE - 1) / (NBPG*CLSIZE);	/* Read them in reverse order into the union which serves */	/* to let us read an even number of clicks even though the user */	/* structure may be smaller than that. */	while (--ncl >= 0) {		i = ncl * CLSIZE;		klseek(fm, (long)ctob(arguutl[CLSIZE+i].pg_pfnum), 0);		if (read(fm, un_user.upages[i], CLSIZE*NBPG) != CLSIZE*NBPG) {			printf("pstat: cant read page %d of u from %s\n",			    arguutl[CLSIZE+i].pg_pfnum, fmem);			return;		}	}	printf("pcb (%d bytes)\n",sizeof(struct pcb));	ip = (int *)&U.u_pcb;	while (ip < (int *)((int)&U.u_pcb + sizeof(struct pcb))) {		if ((ip - (int *)&U.u_pcb) % 4 == 0)			printf("\t");		printf("%9.1x ", *ip++);		if ((ip - (int *)&U.u_pcb) % 4 == 0)			printf("\n");	}	if ((ip - (int *)&U.u_pcb) % 4 != 0)		printf("\n");	printf("procp\t%9.1x\n", U.u_procp);	printf("ar0\t%9.1x\n", U.u_ar0);	printf("comm\t %s\n", U.u_comm);	printf("arg");	for (i=0; i<sizeof(U.u_arg)/sizeof(U.u_arg[0]); i++) {		if (i%5==0) printf("\t");		printf("%9.1x", U.u_arg[i]);		if (i%5==4) printf("\n");	}	printf("\n");	printf("ap\t%9.1x\n", U.u_ap);	printf("qsave");	for (i=0; i<sizeof(label_t)/sizeof(int); i++) {		if (i%5==0) printf("\t");		printf("%9.1x", U.u_qsave.val[i]);		if (i%5==4) printf("\n");	}	printf("\n");	printf("r_val?\t%9.1x %9.1x\n", U.u_r.r_val1, U.u_r.r_val2);	printf("error\t%9.1x\n", U.u_error);	printf("eosys\t%9.1x\n", U.u_eosys);	printf("u_cred\t%x\n",U.u_cred);	/* credentials is now km_alloc-ed -- have to go get them!!! - rr */	klseek(fc,U.u_cred,0);	read(fc,(char *)&ucred,sizeof(struct ucred));	printf("\tref %d\n",ucred.cr_ref);	printf("\tuid\t%d\tgid\t%d\n",ucred.cr_uid,ucred.cr_gid);	printf("\truid\t%d\trgid\t%d\n",ucred.cr_ruid,ucred.cr_rgid);	printf("\tgroups\t");	for (i=0;i<NGROUPS;i++) {		printf("%d",ucred.cr_groups[i]);		if ((i==(NGROUPS/2 - 1))) printf("\n\t\t");		else if (i<NGROUPS-1) putchar(',');	}	printf("\n");	printf("sizes\t%d %d %d (clicks)\n", U.u_tsize, U.u_dsize, U.u_ssize);	printf("ssave");	for (i=0; i<sizeof(label_t)/sizeof(int); i++) {		if (i%5==0)			printf("\t");		printf("%9.1x", U.u_ssave.val[i]);		if (i%5==4)			printf("\n");	}	printf("\n");	printf("u_odsize\t%d\n",U.u_odsize);	printf("u_ossize\t%d\n",U.u_odsize);	printf("u_outime\t%d\n",U.u_outime);	printf("sigs");	for (i=0; i<NSIG; i++) {		if (i % 8 == 0)			printf("\t");		printf("%5.1x ", U.u_signal[i]);		if (i % 8 == 7)			printf("\n");	}	if (NSIG % 8 != 0) printf("\n");	printf("sigmask");	for (i=0; i<NSIG; i++) {		if (i % 8 == 0)			printf("\t");		printf("%5.1x ", U.u_sigmask[i]);		if (i % 8 == 7)			printf("\n");	}	if (NSIG % 8 != 0) printf("\n");	printf("sigonstack\t%9.1x\n",U.u_sigonstack);	printf("sigintr\t%9.1x\n",U.u_sigintr);	printf("oldmask   \t%9.1x\n",U.u_oldmask);	printf("code      \t%9.1x\n", U.u_code);	printf("sigstack  \t%9.1x\t%9.1x\n",		U.u_sigstack.ss_sp,U.u_sigstack.ss_onstack);	printf("file");	if (U.u_of_count != 0) {		ofile_of = (int *) malloc(U.u_of_count*					  sizeof(int));		pofile_of = (char *) 			malloc(U.u_of_count);		klseek(fc,U.u_ofile_of,0);		read(fc,(char *)ofile_of,U.u_of_count*sizeof(int));		klseek(fc,U.u_pofile_of,0);		read(fc,(char *)pofile_of,U.u_of_count);	}	for (i=0; i<U.u_omax; i++) {		if (i > NOFILE_IN_U) 			fp = (int) ofile_of [i - NOFILE_IN_U];		else 			fp = (int)U.u_ofile[i];		if (i % 8 == 0)			printf("\t");		printf("%9.1x", fp);		if (i % 8 == 7)			printf("\n");	}	if (U.u_omax % 8 != 0) printf("\n");	printf("pofile");	for (i=0; i<NOFILE; i++) {		if (i > NOFILE_IN_U) 			fflg = pofile_of [i - NOFILE_IN_U];		else 			fflg = U.u_pofile[i];		if (i % 8 == 0)			printf("\t");		printf("%9.1x",fflg);		if (i % 8 == 7)			printf("\n");	}	if (NOFILE % 8 != 0) printf("\n");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?