学习别人的,记录自己的。
1、sysinfo用法
#include <sys/sysinfo.h>
int sysinfo(struct sysinfo info);
记录了linux中启动时间、内存信息、交换分区、cpu负载等信息。
成功返回0,失败返回-1
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
};
2、statfs用法
#include <sys/vfs.h>
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);
struct statfs{
long f_type; 、/*文件系统类型*/
long f_bsize; /*经过优化的传输块大小*/
long f_blocks; /*文件系统数据块总数*/
long f_bfree; /*文件系统空闲块*/
long f_bavail; /*非超级用户可以用的块数*/
long f_files; /*文件节点总数*/
long f_ffree; /*空闲文件节点总数*/
fsid_t f_fsid; /*文件系统标识*/
long f_namelen; /*文件名的最大长度*/
};