Get hardware information from /proc filesytem in Linux

后端 未结 3 1578
既然无缘
既然无缘 2021-01-14 07:35

I use execv to run lshw command to get the CPU, disk, and memory in C code. But I would like to search another solution to get these information fr

3条回答
  •  隐瞒了意图╮
    2021-01-14 08:31

    1: To get the CPU load use this command :

    top -bn1 | grep load
    

    this will give you output like :

    top - 12:26:20 up 35 min,  2 users,  load average: 0.02, 0.01, 0.00
    

    now parse the load average from above string. 2: To get memory info use this command :

    free -m
    

    This will give you:

    total       used       free     shared    buffers     cached
    Mem:         15926        308      15617          6         15        122
    -/+ buffers/cache:        171      15755
    Swap:            0          0          0
    

    To get the disk info , use this :

    df -H /home/test
    

    This will give you :

    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1       102G  5.4G   91G   6% /
    

    Now from above result parse the content what you want.

提交回复
热议问题