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

📄 systeminfo.h

📁 unix下的各种类行主机下的top原码
💻 H
字号:
/***********************************************************************************
 * class name:CSystemInfo
 * purpose: 得到unix系统中的各项信息
 * Language:c++
 * version:2.5	
 * OS Platform: SunOS 5.7 ,  
 *                    AIX Version 4,  
 *                    HP-UX hpl3000 B.11.00 U 9000/800 (to)
 *                    Compaq Tru64 UNIX V5.0 (Rev. 910) (cpq) (pts/14)
 * Author:shibing(before 2001/11/13), huangjinbing(after 2001/11/14)
 * Date:2001/11/14
 * Cpryight (C)  Nanjing Linkage System Integration CO.,LTD.
 *
 ***********************************************************************************/
 

#ifndef __H_SYS_INFO_GET_
#define __H_SYS_INFO_GET_
#include "machine.h"
#include <sys/types.h>
#include <sys/param.h>	/* This defines BSD */

/*内存信息,返回的是以K为单位整数*/
struct SMemInfo
{
	int real;		 //总真实内存
	int real_free;	//未使用内存
	int swap;		//总交换区大小或总虚拟内存大小,对dec,sun来说是交换区,对aix,hp来说是虚拟内存
	int swap_free;	//空余交换区或空闲虚拟内存
};

/*系统1,5,15分的平均负载,返回是不带百分号的百分数,例如0.23,0.02等*/
struct SLoadAvg
{	double m01;
	double m05;
	double m15;
};

/*系统cpu负载,返回是不带百分号的百分数,例如98.23,0.02等*/
struct SCpuStatus
{	double idle;  	//空闲
	double user;  	//用户
	double kernel;  	//系统或内核
};


/*进程信息*/
struct SPsInfo
{
	int	pid;		/* unique process id */
	char	username[10];	/* login name */
	char	size[10];		/* size with K or M ended*/
	char	ress[10];		/* resident with K or M ended */
	char	state[10];	/* process state */
	char	time[10];		/* time used */
	char	cpu[10];		/* CPU */
	char 	command[64];	/* COMM*/	
};


class CSystemInfo
{
public:
	CSystemInfo();
	~CSystemInfo();
	
private:
	/* 定义系统信息结构及统计信息结构,结构的原型在machine.h中 */
	struct system_info m_sSysInfo;
	struct statics m_sStatics;
	
	/* 调用get_process_info函数用的返回进程信息句柄 */
	caddr_t m_processes; 

	/* 当前路径 */
	char   m_strPath[256];
	
	/* top运行时所需的路径 */
	char   m_strTopPath[256];
	
	/* 计算fnGetPsInfo调用的次数 */
	int m_iCountCall;
	
public:

	/* 初始化,该函数不允许被多次调用! ,返回-1出错,返回0成功*/
	int fnInitialize(); 
	
	/* 取系统cpu负载,iSs为秒数,返回0 */
	int fnGetCpuStatus(SCpuStatus& outCpuStatus);
	
	/* 取内存信息,返回0 */
	int fnGetMemInfo(SMemInfo& outMemInfo);
	
	/* /取系统1,5,15分的平均负载信息 ,返回0*/
	int fnGetLoadAvg(SLoadAvg& outLoadAvg);
	
	/*初始化进程信息*/
	int fnIniPsInfo();
	
	/* 取实际进程数 */
	int fnGetRealPsNum();
	
	/* 取进程信息,
	   返回:0 -成功
	           -1,不能得到进程信息结构,说明所有的进程信息已取完,需重新
                               初始化进程信息,当返回-1时,还可以继续调用该函数
	           -2,错误,可能是权限不够问题
	*/
	int fnGetPsInfo(SPsInfo& outPsInfo);
};

#endif //__H_SYS_INFO_GET_

⌨️ 快捷键说明

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