int init_process_info_sysdep(void) { num_cpus= sysconf( _SC_NPROCESSORS_ONLN); return (getuid()==0); } double timestruc_to_tseconds(timestruc_t t) { return t.tv_sec * 10 + t.tv_nsec / 100000000.0; } int get_process_info_sysdep(ProcInfo_T p) { char buf[4096]; psinfo_t * psinfo= (psinfo_t *)&buf; pstatus_t * pstatus= (pstatus_t *)&buf; if (!read_proc_file(buf,4096, "psinfo", p->pid)) { return FALSE; } /* If we don't have any light-weight processes (LWP) then we are definitely a zombie */ if ( psinfo->pr_nlwp == 0 ) { p->status_flag = PROCESS_ZOMBIE; } if ( p->status_flag != PROCESS_ZOMBIE ) { /* We can't access /proc/$pid/status of a zombie */ /* and does it anyway matter? */ p->mem_percent = psinfo->pr_pctmem * 1000 / 0x8000; p->mem_kbyte = psinfo->pr_rssize; if (!read_proc_file(buf,4096, "status", p->pid)) { return FALSE; } p->cputime_prev= p->cputime; p->cputime= ( timestruc_to_tseconds(pstatus->pr_utime) + timestruc_to_tseconds(pstatus->pr_stime) ); if( include_children ) { p->cputime+= ( timestruc_to_tseconds(pstatus->pr_cutime) + timestruc_to_tseconds(pstatus->pr_cstime) ); } /* first run ? */ if ( p->time_prev == 0.0 ) { p->cputime_prev= p->cputime; } } else { p->cputime_prev= p->cputime = 0; p->mem_kbyte= 0; p->mem_percent= 0.0; } return TRUE; }