/*===========================================================================* * rproc_dmp * *===========================================================================*/ void rproc_dmp() { struct rproc *rp; struct rprocpub *rpub; int i, n=0; static int prev_i=0; if (getsysinfo(RS_PROC_NR, SI_PROCPUB_TAB, rprocpub, sizeof(rprocpub)) != OK || getsysinfo(RS_PROC_NR, SI_PROC_TAB, rproc, sizeof(rproc)) != OK) { printf("Error obtaining table from RS. Perhaps recompile IS?\n"); return; } printf("Reincarnation Server (RS) system process table dump\n"); printf("----label---- endpoint- -pid- flags- -dev- -T- alive_tm starts command\n"); for (i=prev_i; i<NR_SYS_PROCS; i++) { rp = &rproc[i]; rpub = &rprocpub[i]; if (! (rp->r_flags & RS_IN_USE)) continue; if (++n > 22) break; printf("%13s %9d %5d %6s %3d/%1d %3ld %8ld %5dx %s", rpub->label, rpub->endpoint, rp->r_pid, s_flags_str(rp->r_flags, rpub->sys_flags), rpub->dev_nr, rpub->dev_style, rp->r_period, rp->r_alive_tm, rp->r_restarts, rp->r_args ); printf("\n"); } if (i >= NR_SYS_PROCS) i = 0; else printf("--more--\r"); prev_i = i; }
void showtop(int r) { #define NLOADS 3 double loads[NLOADS]; int nloads, i, p, lines = 0; static struct proc prev_proc[PROCS], proc[PROCS]; struct winsize winsize; static struct pm_mem_info pmi; static int prev_uptime, uptime; static struct mproc mproc[NR_PROCS]; struct tms tms; uptime = times(&tms); if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) { perror("TIOCGWINSZ"); fprintf(stderr, "TIOCGWINSZ failed\n"); exit(1); } if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) { fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n"); exit(1);; } if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) { fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n"); exit(1); } if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) { fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n"); exit(1); } if((nloads = getloadavg(loads, NLOADS)) != NLOADS) { fprintf(stderr, "getloadavg() failed - %d loads\n", nloads); exit(1); } printf("%s", Tclr_all); lines += print_load(loads, NLOADS); lines += print_proc_summary(proc); lines += print_memory(&pmi); if(winsize.ws_row > 0) r = winsize.ws_row; print_procs(r - lines - 2, prev_proc, proc, uptime-prev_uptime, mproc); memcpy(prev_proc, proc, sizeof(prev_proc)); prev_uptime = uptime; }
void mproc_dmp() { struct mproc *mp; struct schedproc *schedp; int i, j, n=0, k=0; static int prev_i = 0; static int prev_j = 0; if (getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc, sizeof(mproc)) != OK) { printf("Error obtaining table from PM. Perhaps recompile IS?\n"); return; } if(getsysinfo(SCHED_PROC_NR, SI_PROC_TAB, schedproc,sizeof(schedproc)) != OK){ printf("Error obtaining table from SCHED. Perhaps recompile IS?\n"); return; } printf("Process manager (PM) process table dump\n"); printf("-process- -nr-pnr-tnr- --pid--ppid--pgrp- -uid-- -gid-- -nice- -flags-------\n"); for (i=prev_i; i<NR_PROCS; i++) { mp = &mproc[i]; if (mp->mp_pid == 0 && i != PM_PROC_NR) continue; if (++n > 10) break; printf("%8.8s %d %d %3d %4d %4d %5d ", mp->mp_name, i, mp->mp_scheduler, mp->mp_endpoint, mp->mp_pid, mproc[mp->mp_parent].mp_pid, mp->mp_procgrp); printf("%2d(%2d) %2d(%2d) ", mp->mp_realuid, mp->mp_effuid, mp->mp_realgid, mp->mp_effgid); printf(" %3d %s ", mp->mp_nice, flags_str(mp->mp_flags)); printf("\n"); } printf("Proc\t ParentID\t Counter\t Period\t OnePeriod\t Orig Quantum\n"); for(j=prev_j; j < NR_PROCS; j++){ schedp = &schedproc[j]; if(schedp->period_counter == 0) continue; if (++k > 11) break; printf("%d\t %d\t\t %6d\t\t %5u\t %7u\t %10u \n", schedp->endpoint,schedp->parent,schedp->period_counter,schedp->dyn_period,schedp->curr_periods[0],schedp->orig_quantum); } if (i >= NR_PROCS) i = 0; else printf("--more--\r"); prev_i = i; if (j >= NR_PROCS) j = 0; else printf("j at: %d" ,j); prev_j = j; }
JNIEXPORT jboolean JNICALL Java_jp_co_acroquest_endosnipe_javelin_resource_proc_SolarisResourceReader_openQuery (JNIEnv *env, jobject obj) { kstat_t *kstat_ncpus; kstat_named_t *knamed_ncpus; int result; g_kstat_ctl = kstat_open(); /* get number of cpus */ kstat_ncpus = kstat_lookup(g_kstat_ctl, "unix", 0, "system_misc"); result = kstat_read(g_kstat_ctl, kstat_ncpus, 0); if (result == -1) { return JNI_FALSE; } knamed_ncpus = kstat_data_lookup(kstat_ncpus, "ncpus"); if (knamed_ncpus != NULL) { g_num_cpus = knamed_ncpus->value.ui32; } if (g_num_cpus <= 0) { g_num_cpus = 1; } getsysinfo(&g_system_info_prev); return JNI_TRUE; }
/*===========================================================================* * sigaction_dmp * *===========================================================================*/ void sigaction_dmp() { struct mproc *mp; int i, n=0; static int prev_i = 0; clock_t uptime; if (getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc, sizeof(mproc)) != OK) { printf("Error obtaining table from PM. Perhaps recompile IS?\n"); return; } getuptime(&uptime); printf("Process manager (PM) signal action dump\n"); printf("-process- -nr- --ignore- --catch- --block- -pending- -alarm---\n"); for (i=prev_i; i<NR_PROCS; i++) { mp = &mproc[i]; if (mp->mp_pid == 0 && i != PM_PROC_NR) continue; if (++n > 22) break; printf("%8.8s %3d ", mp->mp_name, i); printf(" %08lx %08lx %08lx ", mp->mp_ignore, mp->mp_catch, mp->mp_sigmask); printf("%08lx ", mp->mp_sigpending); if (mp->mp_flags & ALARM_ON) printf("%8d", mp->mp_timer.tmr_exp_time-uptime); else printf(" -"); printf("\n"); } if (i >= NR_PROCS) i = 0; else printf("--more--\r"); prev_i = i; }
/*===========================================================================* * rproc_dmp * *===========================================================================*/ PUBLIC void rproc_dmp() { struct rproc *rp; int i,j, n=0; static int prev_i=0; getsysinfo(RS_PROC_NR, SI_PROC_TAB, rproc); printf("Reincarnation Server (RS) system process table dump\n"); printf("-----proc---pid-flag--dev- -T---checked----alive-starts-backoff-command (argc)-\n"); for (i=prev_i; i<NR_SYS_PROCS; i++) { rp = &rproc[i]; if (! rp->r_flags & RS_IN_USE) continue; if (++n > 22) break; printf("%9d %5d %s %3d/%2d %3u %8u %8u %4dx %3d %s (%d)", rp->r_proc_nr_e, rp->r_pid, s_flags_str(rp->r_flags), rp->r_dev_nr, rp->r_dev_style, rp->r_period, rp->r_check_tm, rp->r_alive_tm, rp->r_restarts, rp->r_backoff, rp->r_cmd, rp->r_argc ); printf("\n"); } if (i >= NR_SYS_PROCS) i = 0; else printf("--more--\r"); prev_i = i; }
/*===========================================================================* * fproc_dmp * *===========================================================================*/ void fproc_dmp() { struct fproc *fp; int i, n=0; static int prev_i; if (getsysinfo(VFS_PROC_NR, SI_PROC_TAB, fproc, sizeof(fproc)) != OK) { printf("Error obtaining table from VFS. Perhaps recompile IS?\n"); return; } printf("File System (FS) process table dump\n"); printf("-nr- -pid- -tty- -umask- --uid-- --gid-- -ldr- -sus-rev-proc-\n"); for (i=prev_i; i<NR_PROCS; i++) { fp = &fproc[i]; if (fp->fp_pid <= 0) continue; if (++n > 22) break; printf("%3d %4d %2d/%d 0x%05x %2d (%2d) %2d (%2d) %3d %3d %3d ", i, fp->fp_pid, major(fp->fp_tty), minor(fp->fp_tty), fp->fp_umask, fp->fp_realuid, fp->fp_effuid, fp->fp_realgid, fp->fp_effgid, !!(fp->fp_flags & FP_SESLDR), fp->fp_blocked_on, !!(fp->fp_flags & FP_REVIVED) ); if (fp->fp_blocked_on == FP_BLOCKED_ON_OTHER) printf("%4d\n", fp->fp_task); else printf(" nil\n"); } if (i >= NR_PROCS) i = 0; else printf("--more--\r"); prev_i = i; }
PUBLIC void mproc_dmp() { struct mproc *mp; int i, n=0; static int prev_i = 0; printf("Process manager (PM) process table dump\n"); getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc); printf("-process- -nr-pnr-tnr- --pid--ppid--pgrp- -uid-- -gid-- -nice- -flags-------\n"); for (i=prev_i; i<NR_PROCS; i++) { mp = &mproc[i]; if (mp->mp_pid == 0 && i != PM_PROC_NR) continue; if (++n > 22) break; printf("%8.8s %4d%4d%4d %5d %5d %5d ", mp->mp_name, i, mp->mp_parent, mp->mp_tracer, mp->mp_pid, mproc[mp->mp_parent].mp_pid, mp->mp_procgrp); printf("%2d(%2d) %2d(%2d) ", mp->mp_realuid, mp->mp_effuid, mp->mp_realgid, mp->mp_effgid); printf(" %3d %s ", mp->mp_nice, flags_str(mp->mp_flags)); printf("\n"); } if (i >= NR_PROCS) i = 0; else printf("--more--\r"); prev_i = i; }
/*===========================================================================* * root_mtab * *===========================================================================*/ void root_mounts(void) { struct vmnt vmnt[NR_MNTS]; struct vmnt *vmp; struct mproc *rmp; int slot; if (getsysinfo(VFS_PROC_NR, SI_VMNT_TAB, vmnt, sizeof(vmnt)) != OK) return; for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { if (vmp->m_dev == NO_DEV) continue; if (vmp->m_fs_e == PFS_PROC_NR) continue; /* Skip (special case) */ slot = _ENDPOINT_P(vmp->m_fs_e); if (slot < 0 || slot >= NR_PROCS) continue; rmp = &mproc[slot]; buf_printf("%s on %s type %s (%s)\n", vmp->m_mount_dev, vmp->m_mount_path, rmp->mp_name, (vmp->m_flags & VMNT_READONLY) ? "ro" : "rw"); } }
/*===========================================================================* * sigaction_dmp * *===========================================================================*/ PUBLIC void sigaction_dmp() { struct mproc *mp; int i, n=0; static int prev_i = 0; clock_t uptime; printf("Process manager (PM) signal action dump\n"); getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc); getuptime(&uptime); printf("-process- -nr- --ignore- --catch- --block- -tomess- -pending- -alarm---\n"); for (i=prev_i; i<NR_PROCS; i++) { mp = &mproc[i]; if (mp->mp_pid == 0 && i != PM_PROC_NR) continue; if (++n > 22) break; printf("%8.8s %3d ", mp->mp_name, i); printf(" %08x %08x %08x %08x ", mp->mp_ignore, mp->mp_catch, mp->mp_sigmask, mp->mp_sig2mess); printf("%08x ", mp->mp_sigpending); if (mp->mp_flags & ALARM_ON) printf("%8u", mp->mp_timer.tmr_exp_time-uptime); else printf(" -"); printf("\n"); } if (i >= NR_PROCS) i = 0; else printf("--more--\r"); prev_i = i; }
/*===========================================================================* * update_fproc_table * *===========================================================================*/ static int update_fproc_table(void) { /* Get the process table from VFS. */ return getsysinfo(VFS_PROC_NR, SI_PROC_TAB, fproc, sizeof(fproc)); }
void cpu_init(void) { struct tms tms; if (getsysinfo(PM_PROC_NR, SI_KPROC_TAB, prevproc) < 0) { fprintf(stderr, "cannot retrieve kproc table\n"); } prevuptime = times(&tms); }
/*===========================================================================* * data_store_dmp * *===========================================================================*/ void data_store_dmp() { struct data_store *dsp; int i,j, n=0, s; static int prev_i=0; printk("Data Store (DS) contents dump\n"); if((s=getsysinfo(DS_PROC_NR, SI_DATA_STORE, store)) != 0) { printk("Couldn't talk to DS: %d.\n", s); return; } printk("slot key type value\n"); for (i=prev_i; i<NR_DS_KEYS; i++) { dsp = &store[i]; if (! dsp->ds_flags & DS_IN_USE) continue; if (++n > 22) break; printk("%3d %-20s ", i, dsp->ds_key); if(dsp->ds_flags & DS_TYPE_U32) { printk("u32 %lu\n", dsp->ds_val.ds_val_u32); } else if(dsp->ds_flags & DS_TYPE_STR) { printk("str \"%s\"\n", dsp->ds_val.ds_val_str); } else { printk("Bogus type\n"); } } if (i >= NR_DS_KEYS) i = 0; else printk("--more--\r"); prev_i = i; }
int main(int argc, char *argv[]) { int index = 0; struct system_info info_prev; struct system_info info; { jobject obj; Java_jp_co_acroquest_endosnipe_javelin_resource_proc_SolarisResourceReader_openQuery(NULL, obj); } getsysinfo(&info_prev); sleep(2); for (index = 0; index < 100; index++) { long update_delta; long swap_avail; long swap_free; struct process_info info2; getsysinfo(&info); update_delta = info.updates - info_prev.updates; swap_avail = info.swap_avail - info_prev.swap_avail; swap_free = info.swap_free - info_prev.swap_free; printf("sys cpu(%lld/%lld/%lld), memory(%lld/%lld), swap(%ld/%ld), page(%lld/%lld)\n", info.cpu_user, info.cpu_sys, info.cpu_total, info.mem_total, info.mem_total - info.mem_free, swap_avail / update_delta / 1024, (swap_avail + swap_free) / update_delta / 1024, info.page_in, info.page_out); getprocessinfo(&info2); printf("proc cpu(%lld/%lld/%lld), memory(%lld/%lld), thread(%d), majflt(%d)\n", info2.cpu_user, info2.cpu_sys, info2.cpu_total, info2.mem_virtual, info2.mem_physical, info2.threads, info2.majar_fault); info_prev = info; sleep(1); } }
JNIEXPORT jboolean JNICALL Java_jp_co_acroquest_endosnipe_javelin_resource_proc_SolarisResourceReader_collectQueryData (JNIEnv *env, jobject obj) { jboolean result_system; jboolean result_process; g_system_info_prev = g_system_info; result_system = getsysinfo(&g_system_info); result_process = getprocessinfo(&g_process_info); return (result_system == JNI_TRUE) && (result_process == JNI_TRUE); }
/*{ ** Name: axp_osf_get_num_of_processors() - Get number of active processors ** ** Description: ** Return number of processors on the machine. ** On successful completion, getsysinfo() returns a value indicating the ** number of requested items returned. If the information requested is ** not available, it returns a zero. Otherwise -1 is returned. ** ** Inputs: ** none. ** ** Outputs: ** none. ** ** Returns: ** number of processors on the machine. ** ** History: ** 06-jan-94 (johnst) ** Bug #58887 ** Created. ** */ static i4 axp_osf_get_num_of_processors() { i4 num_processors; if (getsysinfo((unsigned long) GSI_MAX_CPU, &num_processors, (unsigned long) sizeof(num_processors), (int *) 0, (char *) 0) <= 0) { /* default to 1 on all errors */ num_processors = 1; } return(num_processors); }
/*===========================================================================* * pscount_dmp * *===========================================================================*/ void pscount_dmp() { struct mproc *mp; int i,n=0; if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc, sizeof(mproc))!=OK){ printf("Error obtaining table from PM. Perhaps recompile IS?\n"); return; } for(i=0;i<NR_PROCS;i++){ mp=&mproc[i]; if(mp->mp_pid==0 && i!=PM_PROC_NR) continue; n++; } printf("Number of running processes: %d\n",n); }
/*===========================================================================* * init_server * *===========================================================================*/ PRIVATE void init_server(void) { /* Initialize the reincarnation server. */ struct sigaction sa; struct boot_image *ip; int s,t; /* Install signal handlers. Ask PM to transform signal into message. */ sa.sa_handler = SIG_MESS; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGCHLD,&sa,NULL)<0) panic("RS","sigaction failed", errno); if (sigaction(SIGTERM,&sa,NULL)<0) panic("RS","sigaction failed", errno); /* Initialize the system process table. Use the boot image from the kernel * and the device map from the FS to gather all needed information. */ if ((s = sys_getimage(image)) != OK) panic("RS","warning: couldn't get copy of image table", s); if ((s = getsysinfo(FS_PROC_NR, SI_DMAP_TAB, dmap)) < 0) panic("RS","warning: couldn't get copy of dmap table", errno); /* Now initialize the table with the processes in the system image. * Prepend /sbin/ to the binaries so that we can actually find them. */ for (s=0; s< NR_BOOT_PROCS; s++) { ip = &image[s]; if (ip->proc_nr >= 0) { nr_in_use ++; rproc[s].r_flags = RS_IN_USE; rproc[s].r_proc_nr_e = ip->endpoint; rproc[s].r_pid = getnpid(ip->proc_nr); for(t=0; t< NR_DEVICES; t++) if (dmap[t].dmap_driver == ip->proc_nr) rproc[s].r_dev_nr = t; strcpy(rproc[s].r_cmd, "/sbin/"); strcpy(rproc[s].r_cmd+6, ip->proc_name); rproc[s].r_argc = 1; rproc[s].r_argv[0] = rproc[s].r_cmd; rproc[s].r_argv[1] = NULL; } } /* Set alarm to periodically check driver status. */ if (OK != (s=sys_setalarm(RS_DELTA_T, 0))) panic("RS", "couldn't set alarm", s); }
/*===========================================================================* * root_dmap * *===========================================================================*/ static void root_dmap(void) { struct dmap dmap[NR_DEVICES]; int i; if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK) return; for (i = 0; i < NR_DEVICES; i++) { if (dmap[i].dmap_driver == NONE) continue; buf_printf("%u %s %u\n", i, dmap[i].dmap_label, dmap[i].dmap_driver); } }
/*===========================================================================* * dtab_dmp * *===========================================================================*/ void dtab_dmp() { int i; if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK) { printf("Error obtaining table from VFS. Perhaps recompile IS?\n"); return; } printf("File System (FS) device <-> driver mappings\n"); printf(" Label Major Driver ept\n"); printf("------------- ----- ----------\n"); for (i=0; i<NR_DEVICES; i++) { if (dmap[i].dmap_driver == NONE) continue; printf("%13s %5d %10d\n", dmap[i].dmap_label, i, dmap[i].dmap_driver); } }
_XkbDDXBeepInitAtoms() #endif { featureOn= MAKE_ATOM(FEATURE_ON); featureOff= MAKE_ATOM(FEATURE_OFF); featureChange= MAKE_ATOM(FEATURE_CHANGE); ledOn= MAKE_ATOM(LED_ON); ledOff= MAKE_ATOM(LED_OFF); ledChange= MAKE_ATOM(LED_CHANGE); slowWarn= MAKE_ATOM(SLOW_WARN); slowPress= MAKE_ATOM(SLOW_PRESS); slowReject= MAKE_ATOM(SLOW_REJECT); slowAccept= MAKE_ATOM(SLOW_ACCEPT); slowRelease= MAKE_ATOM(SLOW_RELEASE); stickyLatch= MAKE_ATOM(STICKY_LATCH); stickyLock= MAKE_ATOM(STICKY_LOCK); stickyUnlock= MAKE_ATOM(STICKY_UNLOCK); bounceReject= MAKE_ATOM(BOUNCE_REJECT); #if (defined(__osf__) && defined(__alpha)) /* [[[ WDW - Some bells do not allow for pitch changes. * Maybe this could become part of the keymap? ]]] */ { char keyboard[8]; /* Find the class of keyboard being used. */ keyboard[0] = '\0'; if (-1 == getsysinfo(GSI_KEYBOARD, keyboard, sizeof(keyboard), 0, NULL)) keyboard[0] = '\0'; if ((strcmp(keyboard,"LK201") == 0) || (strcmp(keyboard,"LK401") == 0) || (strcmp(keyboard,"LK421") == 0) || (strcmp(keyboard,"LK443") == 0)) doesPitch = 0; } #else #if defined(sun) doesPitch = 0; #endif #endif return; }
void get_system_info (struct system_info *si) { long avenrun[3]; struct sysinfo sysinfo; struct vmtotal total; struct anoninfo anoninfo; static time_t cp_old[CPUSTATES]; static time_t cp_diff[CPUSTATES]; /* for cpu state percentages */ register int i; getsysinfo(&sysinfo); /* convert cp_time counts to percentages */ (void) percentages (CPUSTATES, cpu_states, sysinfo.cpu, cp_old, cp_diff); /* Find total CPU utilization, as a fraction of 1. */ total_cpu = (cpu_states[CPU_USER] + cpu_states[CPU_KERNEL]) / 1000.0; /* get mpid -- process id of last process */ (void) getkval (mpid_offset, &(si->last_pid), sizeof (si->last_pid), "mpid"); /* get load average array */ (void) getkval (avenrun_offset, (int *) avenrun, sizeof (avenrun), "avenrun"); /* convert load averages to doubles */ for (i = 0; i < 3; i++) si->load_avg[i] = loaddouble (avenrun[i]); /* get total -- systemwide main memory usage structure */ (void) getkval (total_offset, (int *) (&total), sizeof (total), "total"); /* convert memory stats to Kbytes */ memory_stats[0] = pagetok (total.t_rm); memory_stats[1] = pagetok (total.t_arm); memory_stats[2] = pagetok (total.t_free); (void) getkval (anoninfo_offset, (int *) (&anoninfo), sizeof (anoninfo), "anoninfo"); memory_stats[3] = pagetok (anoninfo.ani_max - anoninfo.ani_free); memory_stats[4] = pagetok (anoninfo.ani_max - anoninfo.ani_resv); /* set arrays and strings */ si->cpustates = cpu_states; si->memory = memory_stats; }
/* * Get the process table from PM. Check the magic number in the table entries. */ static int update_mproc_table(void) { int r, slot; r = getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc, sizeof(mproc)); if (r != OK) return r; for (slot = 0; slot < NR_PROCS; slot++) { if (mproc[slot].mp_magic != MP_MAGIC) { printf("PROCFS: PM version mismatch!\n"); return EINVAL; } } return OK; }
int cpu_get_usage(cpu_options *opts) { struct tms tms; int dt, p, idletime; uptime = times(&tms); dt = uptime - prevuptime; if (getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) { fprintf(stderr, "cannot retrieve kproc table\n"); return 0; } idletime = proc[0].p_user_time - prevproc[0].p_user_time; /* only copy IDLE task, which is the first task in the list */ memcpy(prevproc, proc, sizeof(struct proc)); prevuptime = uptime; return 100 - 100 * idletime / dt; }
/*===========================================================================* * update_mproc_table * *===========================================================================*/ static int update_mproc_table(void) { /* Get the process table from PM. * Check the magic number in the table entries. */ int r, slot; r = getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc, sizeof(mproc)); if (r != OK) return r; for (slot = 0; slot < NR_PROCS; slot++) { if (mproc[slot].mp_magic != MP_MAGIC) { printf("PROCFS: PM version mismatch!\n"); return EINVAL; } } return OK; }
/* getsysinfo is available on OSF, or 4.0 and up at least. The man page (on 4.0) suggests a 0 return indicates information not available, but that seems to be the normal return for GSI_CPU_INFO. */ static int freq_getsysinfo (int help) { #if HAVE_GETSYSINFO struct cpu_info c; int start; HELP ("getsysinfo() GSI_CPU_INFO"); start = 0; if (getsysinfo (GSI_CPU_INFO, (caddr_t) &c, sizeof (c), &start, NULL, NULL) != -1) { speed_cycletime = 1e-6 / (double) c.mhz; if (speed_option_verbose) printf ("Using getsysinfo() GSI_CPU_INFO %u for cycle time %.3g\n", c.mhz, speed_cycletime); return 1; } #endif return 0; }
int main(int argc, char **argv) { struct pciinfo_entry *entry; struct pciinfo pciinfo; /* obtain a list of PCI devices from PM */ if (getsysinfo(PM_PROC_NR, SI_PCI_INFO, &pciinfo) < 0) { perror("getsysinfo failed"); return -1; } /* print the list of devices */ entry = pciinfo.pi_entries; while (pciinfo.pi_count-- > 0) { printf("%.4X:%.4X %s\n", entry->pie_vid, entry->pie_did, entry->pie_name); entry++; } return 0; }
/* Return the total amount of physical memory. */ double physmem_total (void) { #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE { /* This works on linux-gnu, solaris2 and cygwin. */ double pages = sysconf (_SC_PHYS_PAGES); double pagesize = sysconf (_SC_PAGESIZE); if (0 <= pages && 0 <= pagesize) return pages * pagesize; } #endif #if HAVE_PSTAT_GETSTATIC { /* This works on hpux11. */ struct pst_static pss; if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)) { double pages = pss.physical_memory; double pagesize = pss.page_size; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE { /* This works on irix6. */ struct rminfo realmem; if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) { double pagesize = sysconf (_SC_PAGESIZE); double pages = realmem.physmem; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_GETSYSINFO && defined GSI_PHYSMEM { /* This works on Tru64 UNIX V4/5. */ int physmem; if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem), NULL, NULL, NULL) == 1) { double kbytes = physmem; if (0 <= kbytes) return kbytes * 1024.0; } } #endif #if HAVE_SYSCTL && defined HW_PHYSMEM { /* This works on *bsd and darwin. */ unsigned int physmem; size_t len = sizeof physmem; static int mib[2] = { CTL_HW, HW_PHYSMEM }; if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 && len == sizeof (physmem)) return (double) physmem; } #endif #if HAVE__SYSTEM_CONFIGURATION /* This works on AIX 4.3.3+. */ return _system_configuration.physmem; #endif #if defined _WIN32 { /* this works on windows */ PFN_MS_EX pfnex; HMODULE h = GetModuleHandle ("kernel32.dll"); if (!h) return 0.0; /* Use GlobalMemoryStatusEx if available. */ if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) { lMEMORYSTATUSEX lms_ex; lms_ex.dwLength = sizeof lms_ex; if (!pfnex (&lms_ex)) return 0.0; return (double) lms_ex.ullTotalPhys; } /* Fall back to GlobalMemoryStatus which is always available. but returns wrong results for physical memory > 4GB. */ else { MEMORYSTATUS ms; GlobalMemoryStatus (&ms); return (double) ms.dwTotalPhys; } } #endif /* Return 0 if we can't determine the value. */ return 0; }
void showtop(int r) { #define NLOADS 3 double loads[NLOADS]; int nloads, i, p, lines = 0; static struct proc prev_proc[PROCS], proc[PROCS]; static int preheated = 0; struct winsize winsize; /* static struct pm_mem_info pmi; */ static struct mproc mproc[NR_PROCS]; int mem = 0; if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) { perror("TIOCGWINSZ"); fprintf(stderr, "TIOCGWINSZ failed\n"); exit(1); } #if 0 if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) { fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n"); mem = 0; exit(1);; } else mem = 1; #endif retry: if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) { fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n"); exit(1); } if (!preheated) { preheated = 1; memcpy(prev_proc, proc, sizeof(prev_proc)); goto retry;; } if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) { fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n"); exit(1); } if((nloads = getloadavg(loads, NLOADS)) != NLOADS) { fprintf(stderr, "getloadavg() failed - %d loads\n", nloads); exit(1); } printf("%s", Tclr_all); lines += print_load(loads, NLOADS); lines += print_proc_summary(proc); #if 0 if(mem) { lines += print_memory(&pmi); } #endif if(winsize.ws_row > 0) r = winsize.ws_row; print_procs(r - lines - 2, prev_proc, proc, mproc); memcpy(prev_proc, proc, sizeof(prev_proc)); }
int main(int argc, char **args) { getsysinfo(); return 0; }