⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m_umax.c

📁 查看系统硬件和内存资源使用情况;以及各个进程的使用情况
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * top - a top users display for Unix * * SYNOPSIS:  Encore Multimax running any release of UMAX 4.3 * * DESCRIPTION: * This module makes top work on the following systems: *	Encore Multimax running UMAX 4.3 release 4.0 and later * * AUTHOR:  William LeFebvre <wnl@groupsys.com> *//* * The winner of the "wow what a hack" award: * We don't really need the proc structure out of sys/proc.h, but we do * need many of the #defines.  So, we define a bogus "queue" structure * so that we don't have to include that mess of stuff in machine/*.h * just so that the proc struct will get defined cleanly. */struct queue { int x };#include <stdio.h>#include <sys/types.h>#include <sys/param.h>#include <sys/time.h>#include <sys/resource.h>#include <sys/proc.h>#include <machine/cpu.h>#include <inq_stats/statistics.h>#include <inq_stats/cpustats.h>#include <inq_stats/procstats.h>#include <inq_stats/vmstats.h>#include "top.h"#include "display.h"#include "machine.h"#include "utils.h"struct handle{    struct proc **next_proc;	/* points to next valid proc pointer */    int remaining;		/* number of pointers remaining */};/* Log base 2 of 1024 is 10 (2^10 == 1024) */#define LOG1024		10/* Convert clicks (kernel pages) to kbytes ... */#if PGSHIFT>10#define pagetok(size)	((size) << (PGSHIFT - LOG1024))#else#define pagetok(size)	((size) >> (LOG1024 - PGSHIFT))#endif/* what we consider to be process size: */#define PROCSIZE(pp) ((pp)->pd_tsize + (pp)->pd_dsize + (pp)->pd_ssize)/* the ps_nrun array index is incremented every 12th of a minute */#define	MINUTES(x)	((x) * 12)/* convert a tv structure (seconds, microseconds) to a double */#define TVTODOUBLE(tv) ((double)(tv).tv_sec + ((double)(tv).tv_usec / 1000000))/* *  These definitions control the format of the per-process area */static char header[] =  "  PID X        PRI NICE  SIZE   RES STATE    TIME    %CPU COMMAND";/* 0123456   -- field to fill in starts at header+6 */#define UNAME_START 6#define Proc_format \	"%5d %-8.8s %3d %4d %5s %5s %-5s %6s %6.2f%% %s"/* process state names for the "STATE" column of the display */char *state_abbrev[] ={    "", "", "wait", "run", "start", "stop", "exec", "event"};/* these are for detailing the process states */int process_states[5];char *procstatenames[] = {    " waiting, ",#define P_SLEEP  0    " running, ",#define P_RUN    1    " zombie, ",#define P_ZOMBIE 2    " stopped, ",#define P_STOP   3    " free slots",#define P_FREE   4    NULL};/* these are for detailing the cpu states */int cpu_states[4];char *cpustatenames[] = {    "user", "nice", "system", "idle", NULL};/* these are for detailing the memory statistics */int memory_stats[4];char *memorynames[] = {    "K available, ", "K free, ", "K locked, ", "K virtual", NULL};/* these detail per-process information */static int nprocs;static int pref_len;static struct proc_detail *pd;static struct proc_detail **pref;/* inq_stats structures and the STAT_DESCRs that use them */static struct proc_config stat_pc;static struct vm_config stat_vm;static struct class_stats stat_class;static struct proc_summary stat_ps;static struct cpu_stats stat_cpu;static struct stat_descr sd_procconfig = {    NULL,		/* sd_next */    SUBSYS_PROC,	/* sd_subsys */    PROCTYPE_CONFIG,	/* sd_type */    0,			/* sd_options */    0,			/* sd_objid */    &stat_pc,		/* sd_addr */    sizeof(stat_pc),	/* sd_size */    0,			/* sd_status */    0,			/* sd_sizeused */    0			/* sd_time */};static struct stat_descr sd_memory = {    NULL,		/* sd_next */    SUBSYS_VM,		/* sd_subsys */    VMTYPE_SYSTEM,	/* sd_type */    0,			/* sd_options */    0,			/* sd_objid */    &stat_vm,		/* sd_addr */    sizeof(stat_vm),	/* sd_size */    0,			/* sd_status */    0,			/* sd_sizeused */    0			/* sd_time */};static struct stat_descr sd_class = {    NULL,		/* sd_next */    SUBSYS_CPU,		/* sd_subsys */    CPUTYPE_CLASS,	/* sd_type */    0,			/* sd_options */    UMAXCLASS,		/* sd_objid */    &stat_class,	/* sd_addr */    sizeof(stat_class),	/* sd_size */    0,			/* sd_status */    0,			/* sd_sizeused */    0			/* sd_time */};static struct stat_descr sd_procsummary = {    NULL,		/* sd_next */    SUBSYS_PROC,	/* sd_subsys */    PROCTYPE_SUMMARY,	/* sd_type */    0,			/* sd_options */    0,			/* sd_objid */    &stat_ps,		/* sd_addr */    sizeof(stat_ps),	/* sd_size */    0,			/* sd_status */    0,			/* sd_sizeused */    0			/* sd_time */};static struct stat_descr sd_procdetail = {    NULL,		/* sd_next */    SUBSYS_PROC,	/* sd_subsys */    PROCTYPE_DETAIL,	/* sd_type */    PROC_DETAIL_ALL | PROC_DETAIL_ALLPROC,	/* sd_options */    0,			/* sd_objid */    NULL,		/* sd_addr */    0,			/* sd_size */    0,			/* sd_status */    0,			/* sd_sizeused */    0			/* sd_time */};static struct stat_descr sd_cpu = {    NULL,		/* sd_next */    SUBSYS_CPU,		/* sd_subsys */    CPUTYPE_CPU,	/* sd_type */    0,			/* sd_options */    0,			/* sd_objid */    &stat_cpu,		/* sd_addr */    sizeof(stat_cpu),	/* sd_size */    0,			/* sd_status */    0,			/* sd_sizeused */    0			/* sd_time */};/* precomputed values */static int numcpus;machine_init(statics)struct statics *statics;{    if (inq_stats(2, &sd_procconfig, &sd_class) == -1)    {	perror("proc config");	return(-1);    }    if (sd_procconfig.sd_status != 0)    {	fprintf(stderr, "stats status %d\n", sd_procconfig.sd_status);    }	#ifdef DEBUG    printf("pc_nprocs = %d\n", stat_pc.pc_nprocs);    printf("class_numcpus = %d\n", stat_class.class_numcpus);#endif    /* things to remember */    numcpus = stat_class.class_numcpus;    /* space to allocate */    nprocs = stat_pc.pc_nprocs;    pd = (struct proc_detail *)malloc(nprocs * sizeof(struct proc_detail));    pref = (struct proc_detail **)malloc(nprocs * sizeof(struct proc_detail *));    if (pd == NULL || pref == NULL)    {	fprintf(stderr, "top: can't allocate sufficient memory\n");	return(-1);    }    /* pointers to assign */    sd_procdetail.sd_addr = pd;    sd_procdetail.sd_size = nprocs * sizeof(struct proc_detail);    /* fill in the statics stuff */    statics->procstate_names = procstatenames;    statics->cpustate_names = cpustatenames;    statics->memory_names = memorynames;    return(0);}char *format_header(uname_field)register char *uname_field;{    register char *ptr;    ptr = header + UNAME_START;    while (*uname_field != '\0')    {	*ptr++ = *uname_field++;    }    return(header);}get_system_info(si)struct system_info *si;{    /* get all status information at once */    inq_stats(1, &sd_memory);    /* fill in the memory statistics, converting to K */    memory_stats[0] = pagetok(stat_vm.vm_availmem);    memory_stats[1] = pagetok(stat_vm.vm_freemem);    memory_stats[2] = pagetok(stat_vm.vm_physmem - stat_vm.vm_availmem);    memory_stats[3] = 0;   /* ??? */    /* set array pointers */    si->cpustates = cpu_states;    si->memory = memory_stats;}static struct handle handle;caddr_t get_process_info(si, sel, compare)struct system_info *si;struct process_select *sel;int (*compare)();{    register int i;    register int index;    register int total;    int active_procs;    char show_idle;    char show_system;    char show_uid;    char show_command;

⌨️ 快捷键说明

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