易截截图软件、单文件、免安装、纯绿色、仅160KB

编程获取linux的cpu占用率和mem和硬盘使用情况

linux下提供top、ps命令查看当前cpu、mem使用情况,简要介绍如下:
一、使用ps查看进程的资源占用
ps -aux查看进程信息时,第三列就是CPU占用。
[root@localhost utx86]# ps -aux | grep my_process
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root   14415  3.4  0.9   37436  20328  pts/12   SL+  14:18   0:05 ./my_process
root   14464  0.0   0.0   3852   572    pts/3    S+   14:20   0:00 grep my_process
每一列含义如下
USER   PID   %CPU %MEM  VSZ  RSS TTY  STAT   START  TIME   COMMAND
即my_process进程当前占用cpu 3.4%, 内存0.9%
二、top动态查看系统负荷
top -n 1显示后退出
[root@localhost utx86]# top -n 1
top - 14:23:20 up  5:14, 14 users,  load average: 0.00, 0.04, 0.01
Tasks: 183 total,   1 running, 181 sleeping,   1 stopped,   0 zombie
Cpu(s):  1.8%us,  1.4%sy,  0.0%ni, 95.8%id,  0.7%wa,  0.1%hi,  0.2%si,  0.0%st
Mem:   2066240k total,  1507316k used,   558924k free,   190472k buffers
Swap:  2031608k total,       88k used,  2031520k free,  1087184k cached
1、获取cpu占用情况
[root@localhost utx86]# top -n 1 |grep Cpu
Cpu(s):  1.9%us,  1.3%sy,  0.0%ni, 95.9%id,  0.6%wa,  0.1%hi,  0.2%si,  0.0%st
解释:1.9%us是用户占用cpu情况
      1.3%sy,是系统占用cpu情况
得到具体列的值:
[root@localhost utx86]# top -n 1 |grep Cpu | cut -d "," -f 1 | cut -d ":" -f 2
  1.9%us
[root@localhost utx86]# top -n 1 |grep Cpu | cut -d "," -f 2
  1.3%sy
2、获得内存占用情况
[root@localhost utx86]# top -n 1 |grep Mem
Mem:   2066240k total,  1515784k used,   550456k free,   195336k


相关文档:

实战Linux Bluetooth编程(六) L2CAP编程实例

例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
 如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

Linux中的延时函数及获取系统时间函数

应用层:
   #include <unistd.h>
 
   1、unsigned int sleep(unsigned int seconds); 秒级
   2、int usleep(useconds_t usec);              微秒级:1/10^-6 
 
   #define _PO ......

Linux netfilter源码分析(2)

转贴自http://alexanderlaw.blog.hexun.com/8968771_d.html
二、ipt_table数据结构和表的初始化
 
2.1  include/linux/netfilter_ipv4/ip_tables.h   struct  ipt_table 表结构
struct ipt_table
{
struct list_head list;
/* 表链 */
char name[IPT_TABLE_MAXNAMELEN];
/* 表名,如"fil ......

Linux环境进程间通信(二)(上)


Linux环境进程间通信(二):
信号(上)
文档选项
&lt;tr
valign=&quot;top&quot;&gt;&lt;td width=&quot;8&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;1&quot; width=&quot;8&quot;
src=&quot;//www.ibm.com/i/c.gif&quot;/&gt;&a ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号