易截截图软件、单文件、免安装、纯绿色、仅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编程(三) HCI层编程

1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI)  就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......

实战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下修改本机Ip地址的方法

#vi /etc/sysconfig/network-scripts/ifcfg-eth0
内容如下。
DEVICE=eth0
BOOTPROTO=none
IPADDR=192.168.1.115
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=00:25:11:E2:2E:53
ONBOOT=yes
TYPE=Ethernet
......

linux mysql配置


卸载mysql
1、查找以前是否装有mysql
命令:rpm -qa|grep -i mysql
可以看到mysql的两个包:
mysql-4.1.12-3.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
2、删除mysql
删除命令:rpm -e --nodeps 包名
( rpm -ev mysql-4.1.12-3.RHEL4.1 )
3、删除老版本mysql的开发头文件和库
命令:rm -fr /usr/lib/mysql
r ......

Linux 关机指令

1关机命令 shutdown 1)shutdown --help
2)shutdown -h now 现在立即关机 == halt 指令
3)shutdown -r now 现在立即重启
4)shutdown -r +3 三分钟后重启
5)shutdown -h +3 "The System will shutdown after 3 minutes" 提示使用者将在三分钟后关机
6)shutdown -r 20:23 在20:23时将重启计算机
7)shutdown ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号