Linux下用来获取各种系统信息的C++类

该C++类库提供获取Linux系统、内核、进程的实时信息功能,包括CPU、内存、进程状态、内核版本和网卡流量等数据。
摘要由CSDN通过智能技术生成
#include <vector>   
#include "sys/config.h"   
SYS_NAMESPACE_BEGIN   
        
/***   
  * 用来获取系统、内核和进程的各类实时信息,如CPU和内存数据   
  */
class CInfo   
{   
public:   
    /***   
      * 系统当前实时信息   
      */
    typedef struct
    {   
        long uptime_second;             /* Seconds since boot */
        unsigned long average_load[3];  /* 1, 5, and 15 minute load averages */
        unsigned long ram_total;        /* Total usable main memory size */
        unsigned long ram_free;         /* Available memory size */
        unsigned long ram_shared;       /* Amount of shared memory */
        unsigned long ram_buffer;       /* Memory used by buffers */
        unsigned long swap_total;       /* Total swap space size */
        unsigned long swap_free;        /* swap space still available */
        unsigned short process_number;  /* Number of current processes */
    }sys_info_t;   
        
    /***   
      * 当前进程时间信息   
      */
    typedef struct
    {   
        long user_time;             /* user time */
        long system_time;          /* system time */
        long user_time_children;    /* user time of children */
        long system_time_children; /* system time of children */
    }process_time_t;   
        
    /***   
      * 当前系统CPU信息   
      */
    typedef struct
    {   
        // 单位: jiffies, 1jiffies=0.01秒   
        uint64_t total;   
        uint32_t user;    /** 从系统启动开始累计到当前时刻,处于用户态的运行时间,不包含 nice值为负进程 */
        uint32_t nice;    /** 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间 */
        uint32_t system;  /** 从系统启动开始累计到当前时刻,处于核心态的运行时间 */
        uint32_t idle;    /** 从系统启动开始累计到当前时刻,除IO等待时间以外的其它等待时间 */
        uint32_t iowait;  /** 从系统启动开始累计到当前时刻,IO等待时间(2.5.41) */
        uint32_t irq;     /** 从系统启动开始累计到当前时刻,硬中断时间(2.6.0) */
        uint32_t softirq; /** 从系统启动开始累计到当前时刻,软中断时间(2.6.0) */
        //uint32_t stealstolen; /** which is the time spent in other operating systems when running in a virtualized environment(2.6.11) */   
        //uint32_t guest;       /** which is the time spent running a virtual  CPU  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值