linux c io(linux查看io高的进程)
怎么查看linux的哪个进程占用磁盘io较多
您好,很高兴为您解答。
服务器cpu使用率不高,load比较高,所以要查看一下IO。硬盘IO可以通过命令vmstat或iostat获得(也可以用yum安装dstat获得),网络IO可以用iftop命令获取。但是不知道那个进程使用硬盘IO比较高,通过查找没有找到相关命令,只好自己写个脚本进行统计处理。
本脚本在CentOS6下(kernel2.6以上)python2.6测试通过。
直接运行脚本,默认情况下收集3秒钟数据,显示读写最高的前三个进程。如用参数可以使用命令“python fhip.py 4 5 3”,第一个数位每次收集读写数据的间隔秒数,第二个数是打印出读写最多的n个进程,第三个为运行脚本的次数。因为参数部分写的比较简单那,所以用参数必须3个全写。。
#!/bin/python
#-*-coding:utf-8-*-
#Filename:ind_high_io_process
#Revision:1.0
#Date:2013-3-8
#Author:simonzhang
#web:www.simonzhang.net
#Email:simon-zzm@163.com
###ENDINITINFO
importos
importre
importsys
importtime
fromstringimportstrip
####
sys_proc_path='/proc/'
re_find_process_number='^\d+$'
####
#通过/proc/$pid/io获取读写信息
####
defcollect_info():
_tmp={}
re_find_process_dir=re.compile(re_find_process_number)
foriinos.listdir(sys_proc_path):
ifre_find_process_dir.search(i):
#获得进程名
process_name=open("%s%s/stat"%(sys_proc_path,i),"rb").read().split("")[1]
#读取io信息
rw_io=open("%s%s/io"%(sys_proc_path,i),"rb").readlines()
for_infoinrw_io:
cut_info=strip(_info).split(':')
ifstrip(cut_info[0])=="read_bytes":
read_io=int(strip(cut_info[1]))
ifstrip(cut_info[0])=="write_bytes":
write_io=int(strip(cut_info[1]))
_tmp[i]={"name":process_name,"read_bytes":read_io,"write_bytes":write_io}
return_tmp
defmain(_sleep_time,_list_num):
_sort_read_dict={}
_sort_write_dict={}
#获取系统读写数据
process_info_list_frist=collect_info()
time.sleep(_sleep_time)
process_info_list_second=collect_info()
#将读数据和写数据进行分组,写入两个字典中
forloopinprocess_info_list_second.keys():
second_read_v=process_info_list_second[loop]["read_bytes"]
second_write_v=process_info_list_second[loop]["write_bytes"]
try:
frist_read_v=process_info_list_frist[loop]["read_bytes"]
except:
frist_read_v=0
try:
frist_write_v=process_info_list_frist[loop]["write_bytes"]
except:
frist_write_v=0
#计算第二次获得数据域第一次获得数据的差
_sort_read_dict[loop]=second_read_v-frist_read_v
_sort_write_dict[loop]=second_write_v-frist_write_v
#将读写数据进行排序
sort_read_dict=sorted(_sort_read_dict.items(),key=lambda_sort_read_dict:_sort_read_dict[1],reverse=True)
sort_write_dict=sorted(_sort_write_dict.items(),key=lambda_sort_write_dict:_sort_write_dict[1],reverse=True)
#打印统计结果
print"pidprocessread(bytes)pidprocesswrite(btyes)"
for_numinrange(_list_num):
read_pid=sort_read_dict[_num][0]
write_pid=sort_write_dict[_num][0]
res="%s"%read_pid
res+=""*(8-len(read_pid))+process_info_list_second[read_pid]["name"]
res+=""*(12-len(process_info_list_second[read_pid]["name"]))+"%s"%sort_read_dict[_num][1]
res+=""*(12-len("%s"%sort_read_dict[_num][1]))+write_pid
res+=""*(8-len(write_pid))+process_info_list_second[write_pid]["name"]
res+=""*(12-len("%s"%process_info_list_second[write_pid]["name"]))+"%s"%sort_write_dict[_num][1]
printres
print"\n"*1
if__name__=='__main__':
try:
_sleep_time=sys.argv[1]
except:
_sleep_time=3
try:
_num=sys.argv[2]
except:
_num=3
try:
loop=sys.argv[3]
except:
loop=1
foriinrange(int(loop)):
main(int(_sleep_time),int(_num))
如若满意,请点击【采纳答案】,如若还有问题,请点击【追问】
希望我的回答对您有所帮助,望采纳!
~ O(∩_∩)O~
linux内核打印linux内核打印
linuxconsole是什么文件
linuxconsole是一个为内核提供打印的缓冲文件。
linux系统下的打印机无法打印怎么解决?
点击屏幕左下角的“开始”按钮,从弹出的菜单列表中选择“打印机和传真”;
在打开的“打印机和传真”窗口中单击左侧的“添加打印机”命令;
接着会弹出“添加打印机向导”对话框,单击“下一步”按钮继续;
一般我们是选择第一项,使用网络打印机也更多的选.
Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。
它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。
Linux操作系统诞生于1991年10月5日(这是第一次正式向外公布时间)。Linux存在着许多不同的Linux版本,但它们都使用了Linux内核。
Linux可安装在各种计算机硬件设备中,比如手机、平板电脑、路由器、视频游戏控制台、台式计算机、大型机和超级计算机。
严格来讲,Linux这个词本身只表示Linux内核,但实际上人们已经习惯了用Linux来形容整个基于Linux内核,并且使用GNU工程各种工具和数据库的操作系统。
在Linux下查自己的IP怎么查?
可以使用ifconfig命令查看IP。
ifconfig命令用于配置和显示Linux内核中网络接口的网络参数。
输入ifconfig,会打印出网络接口的参数,除了IP地址还会打印出物理地址、掩码地址等网络接口相关参数.
linuxdmesg命令详解?
linuxdmesg命令参数及用法详解(linux显示开机信息命令)
功能说明:显示开机信息。
语法:dmesg
补充说明:kernel会将开机信息存储在ringbuffer中。您若是开机时来不及查看信息,可利用dmesg来查看。开机信息亦保存在/var/log目录中,名称为dmesg的文件里。
参数:
-c显示信息后,清除ringbuffer中的内容。
-s缓冲区大小>预设置为8196,刚好等于ringbuffer的大小。
-n设置记录信息的层级。扩展阅读一:dmesg命令主要用途
主要应用:
dmesg用来显示内核环缓冲区(kernel-ringbuffer)内容,内核将各种消息存放在这里。在系统引导时,内核将与硬件和模块初始化相关的信息填到这个缓冲区中。内核环缓冲区中的消息对于诊断系统问题通常非常有用。在运行dmesg时,它显示大量信息。通常通过less或grep使用管道查看dmesg的输出,这样可以更容易找到待查信息。例如,如果发现硬盘性能低下,可以使用dmesg来检查它们是否运行在DMA模式:
$dmesg|grepDMA
...
ide0:BM-DMAat0xf000-0xf007,BIOSsettings:hda:DMA,hdb:DMA
ide1:BM-DMAat0xf008-0xf00f,BIOSsettings:hdc:DMA,hdd:DMA
...上面几行可以说明每个IDE设备正在什么模式下运行。如果以太网连接出现问题,那么可以在dmesg日志中搜索eth:
$dmesg|grepeth
forcedeth.c:ReverseEngineerednForce
ethernetdriver.Version0.49.
eth0:forcedeth.c:subsystem:0147b:1c00
boundto0000:00:04.0
eth0:noIPv6routerspresent如果一切正常,那么dmesg显示每个网卡的硬件配置信息。如果某项系统服务未能得到正确的配置,dmesg日志很快就填满错误消息,这是诊断故障的良好起点。
还可以用来探测系统内核模块的加载情况,比如要检测ACPI的加载情况,使用dmesg|grepacpi
dmesg|egrep-i''(apm|acpi)''
Kernelcommandline:vga=274quietconsole=ttyS3,9600acpi=no-idleoot=/dev/hda3
ACPI:CoreSubsystemversion
ACPI:Subsystemenabled
ACPI:Systemfirmwaresupports:C2
ACPI:plvl2lat=99plvl3lat=1001
ACPI:C2enter=1417C2exit=354
ACPI:C3enter=-1C3exit=-1
ACPI:NotusingACPIidle
ACPI:Systemfirmwaresupports:S0S1S4S5
扩展阅读二:dmesg命令使用示例
使用示例
示例一将开机信息发邮件
mandmesg写道
Theprogramhelpsuserstoprintouttheirbootupmessages.Insteadofcopyingthemessagesbyhand,theuserneedonly:
dmesg>boot.messages
andmailtheboot.messagesfiletowhoevercandebugtheirproblem.
#dmesg>boot.messages
#ls-lboot.messages
-rw-r--r--1rootroot1583812-0912begin_of_the_skype_highlighting
1583812-0912免费end_of_the_skype_highlighting:55boot.messages#mail-s"BootLogofLinuxServer"public@web3q.netboot.messages
#示例二浏览dmesg输出的信息
#uname-a
Linuxnew552.6.18-194.el5#1SMPTueMar1621:52:43EDT2010i686i686i386GNU/Linux#dmesg|less
Linuxversion2.6.18-194.el5(mockbuild@x86-007.build.bos.redhat.com)(gccversion4.1.220080704(RedHat4.1.2-48))#1SMPTueMar1621:52:43EDT2010
BIOS-providedphysicalRAMmap:
BIOS-e820:0000000000010000-000000000009fc00(usable)
BIOS-e820:000000000009fc00-00000000000a0000(reserved)
BIOS-e820:00000000000e0000-0000000000100000(reserved)
BIOS-e820:0000000000100000-000000001f7d0000(usable)
BIOS-e820:000000001f7d0000-000000001f7efc00(reserved)
BIOS-e820:000000001f7efc00-000000001f7fb000(ACPINVS)
BIOS-e820:000000001f7fb000-000000001f800000(reserved)
BIOS-e820:00000000e0000000-00000000f0000000(reserved)
BIOS-e820:00000000fec00000-00000000fec02000(reserved)
BIOS-e820:00000000fed20000-00000000fed9b000(reserved)
BIOS-e820:00000000feda0000-00000000fedc0000(reserved)
BIOS-e820:00000000ffb00000-00000000ffc00000(reserved)
BIOS-e820:00000000fff00000-0000000100000000(reserved)
0MBHIGHMEMavailable.
503MBLOWMEMavailable.
Memoryforcrashkernel(0x0to0x0)notwithinpermissiblerange
disablingkdump
Usingx86segmentlimitstoapproximateNXprotection
Onnode0totalpages:128976
DMAzone:4096pages,LIFObatch:0
Normalzone:124880pages,LIFObatch:31
DMI2.3present.
UsingAPICdriverdefault
ACPI:RSDP(v000HP)@0x000fe270
ACPI:RSDT(v001HP30C40x31100620HP0x00000001)@0x1f7efc84
ACPI:FADT(v002HP30C40x00000002HP0x00000001)@0x1f7efc00
ACPI:MADT(v001HP30C40x00000001HP0x00000001)@0x1f7efcb8
ACPI:MCFG(v001HP30C40x00000001HP0x00000001)@0x1f7efd14
ACPI:SSDT(v001HPHPQPpc0x00001001MSFT0x0100000e)@0x1f7f6698
ACPI:DSDT(v001HPDAU000x00010000MSFT0x0100000e)@0x00000000
ACPI:PM-TimerIOPort:0x1008
ACPI:LocalAPICaddress0xfec01000
ACPI:LAPIC(acpi_idlapic_idenabled)
Processor#06:13APICversion20
ACPI:LAPIC_NMI(acpi_idhighedgelint)
ACPI:IOAPIC(idaddressgsi_base)
IOAPIC:apic_id1,version32,address0xfec00000,GSI0-23
:
示例三查看dmesg尾部的信息
#dmesg|tail
Bluetooth:L2CAPver2.8
Bluetooth:L2CAPsocketlayerinitialized
Bluetooth:RFCOMMsocketlayerinitialized
Bluetooth:RFCOMMTTYlayerinitialized
Bluetooth:RFCOMMver1.8
Bluetooth:HIDP(HumanInterfaceEmulation)ver1.1
eth0:noIPv6routerspresent
Installingknfsd(copyright(C)1996okir@monad.swb.de).
NFSD:Using/var/lib/nfs/v4recoveryastheNFSv4staterecoverydirectory
NFSD:starting90-secondgraceperiod
#
示例四安装SS7卡驱动时的内核日志
#cdSS7HD_DRIVER/
#ls
bbdddlnx_iss.hbbd_hbi.hbbd_ioc.cbbd_isr.cbbd_pci.cBSD_license.txtGPL_V2-only_license.txtinstall_ss7hd.shMakefile26
bbd_def.hbbd_hs.cbbd_ioc.hbbd_lnx.cbbd_pro.hbuild_ss7hd.shi21555.hMakefile24
#./build_ss7hd.sh
make:Enteringdirectory`/usr/src/kernels/2.6.9-22.EL-i686'
CC/root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_hs.o
CC/root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_ioc.o
CC/root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_isr.o
CC/root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_pci.o
CC/root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_lnx.o
LD/root/setup/ss7dpklnx/SS7HD_DRIVER/ss7hddvr26.o
Buildingmodules,stage2.
MODPOST
CC/root/setup/ss7dpklnx/SS7HD_DRIVER/ss7hddvr26.mod.o
LD/root/setup/ss7dpklnx/SS7HD_DRIVER/ss7hddvr26.ko
make:Leavingdirectory`/usr/src/kernels/2.6.9-22.EL-i686'
#lsmod|grepss7
ss7hddvr26258080
#dmesg|tail
ACPI:PCIinterrupt0000:02:0d.0->GSI9(level,low)->IRQ9
BBD64bit
SS7HD-suspend
DialogicSS7HDDeviceDriverV100.00(SourceV1.21)
Copyright(C)DialogicCorporation2003-2010.AllRightsReserved
Usingmajordevicenumber251.
ACPI:PCIinterrupt0000:02:0d.0->GSI9(level,low)->IRQ9
BBD64bit
#./install_ss7hd.shremove
#lsmod|grepss7
#dmesg|tail
BBD64bit
SS7HD-suspend
DialogicSS7HDDeviceDriverV100.00(SourceV1.21)
Copyright(C)DialogicCorporation2003-2010.AllRightsReserved
Usingmajordevicenumber251.
ACPI:PCIinterrupt0000:02:0d.0->GSI9(level,low)->IRQ9
BBD64bit
SS7HD-suspend
#
示例五打印并清除内核环形缓冲区
#dmesg-c
Linuxversion2.6.18-194.el5(mockbuild@x86-007.build.bos.redhat.com)(gccversion4.1.220080704(RedHat4.1.2-48))#1SMPTueMar1621:52:43EDT2010
BIOS-providedphysicalRAMmap:
BIOS-e820:0000000000010000-000000000009fc00(usable)
BIOS-e820:000000000009fc00-00000000000a0000(reserved)
BIOS-e820:00000000000e0000-0000000000100000(reserved)
BIOS-e820:0000000000100000-000000001f7d0000(usable)
BIOS-e820:000000001f7d0000-000000001f7efc00(reserved)
BIOS-e820:000000001f7efc00-000000001f7fb000(ACPINVS)
BIOS-e820:000000001f7fb000-000000001f800000(reserved)
BIOS-e820:00000000e0000000-00000000f0000000(reserved)
BIOS-e820:00000000fec00000-00000000fec02000(reserved)
BIOS-e820:00000000fed20000-00000000fed9b000(reserved)
BIOS-e820:00000000feda0000-00000000fedc0000(reserved)
BIOS-e820:00000000ffb00000-00000000ffc00000(reserved)
BIOS-e820:00000000fff00000-0000000100000000(reserved)
0MBHIGHMEMavailable.
503MBLOWMEMavailable.
Memoryforcrashkernel(0x0to0x0)notwithinpermissiblerange
disablingkdump
Usingx86segmentlimitstoapproximateNXprotection
Onnode0totalpages:128976
DMAzone:4096pages,LIFObatch:0
Normalzone:124880pages,LIFObatch:31
DMI2.3present.省略输出
Bluetooth:HIDP(HumanInterfaceEmulation)ver1.1
eth0:noIPv6routerspresent
Installingknfsd(copyright(C)1996okir@monad.swb.de).
NFSD:Using/var/lib/nfs/v4recoveryastheNFSv4staterecoverydirectory
NFSD:starting90-secondgraceperiod
#dmesg#less/var/log/dmesg
Linuxversion2.6.18-194.el5(mockbuild@x86-007.build.bos.redhat.com)(gccversion4.1.220080704(RedHat4.1.2-48))#1SMPTueMar1621:52:43EDT2010
BIOS-providedphysicalRAMmap:
BIOS-e820:0000000000010000-000000000009fc00(usable)
BIOS-e820:000000000009fc00-00000000000a0000(reserved)
BIOS-e820:00000000000e0000-0000000000100000(reserved)
BIOS-e820:0000000000100000-000000001f7d0000(usable)
BIOS-e820:000000001f7d0000-000000001f7efc00(reserved)
BIOS-e820:000000001f7efc00-000000001f7fb000(ACPINVS)
BIOS-e820:000000001f7fb000-000000001f800000(reserved)
BIOS-e820:00000000e0000000-00000000f0000000(reserved)
BIOS-e820:00000000fec00000-00000000fec02000(reserved)
BIOS-e820:00000000fed20000-00000000fed9b000(reserved)
BIOS-e820:00000000feda0000-00000000fedc0000(reserved)
BIOS-e820:00000000ffb00000-00000000ffc00000(reserved)
BIOS-e820:00000000fff00000-0000000100000000(reserved)
0MBHIGHMEMavailable.
503MBLOWMEMavailable.
Memoryforcrashkernel(0x0to0x0)notwithinpermissiblerange
disablingkdump
Usingx86segmentlimitstoapproximateNXprotection
Onnode0totalpages:128976
DMAzone:4096pages,LIFObatch:0
Normalzo
linux是dos吗linux是dos
dos和linux中有哪些命令相同?
dos和linux是两套操作系统,网络命令应该相同,比如:ping,telnet等等。
dos和unix和linux哪个是操作系统?
dos和unix和linux三个都是操作系统。dos经典操作系统,已被淘汰,演化成Windows中的命令提示符;Unix是操作系统老牌,演化为MacOS,Solaris,FreeBSD,NetBSD,OpenBSD等,一般用于服务器;linux是一种借鉴Unix的开源、免费的系统,版本多,一般面向桌面系统。
DOS用什么编写的?
DOS/Windows/Linux内核部分全部是基于汇编和C语言来编写的。其中C语言占90%以上的代码量,并实现主要的操作系统功能。无比强大的C
DOS、OS/2、UNIX、XENIX、LINUX、Windows2000、Netware是什么意思?
DOS,是磁碟操作系统(英文:DiskOperatingSystem)的缩写OS/2是由微软和IBM公司共同创造,后来由IBM单独开发的一套操作系统。OS/2是"OperatingSystem/2"的缩写Unix-UNIX,是一个强大的多用户、多任务操作系统XENIX微软开发的用于PC机的UNIX操作系统Linux-Linux是一种类似于UNIX计算机操作系统Windows2000基于NT技术构建。功能性能较为完善的操作系统Netware是NOVELL公司推出的网络操作系统。Netware最重要的特征是基于基本模块设计思想的开放式系统结构
什么叫ms-dos操作系统?
MS-DOS(微软磁盘操作系统),是美国微软公司提供的磁盘操作系统。
单用户单任务OS指只允许一个用户上机,且只允许用户程序作为一个任务运行。MS-DOS属于单用户单任务操作系统。
MS-DOS使用者可通过编辑2个位于开机磁盘根目录的系统档案来达到调控系统组态之目的,它们分别是CONFIG.SYS及AUTOEXEC.BAT,IO.SYS会检视CONFIG.SYS以加载指定的硬体驱动程序,则自动执行AUTOEXEC.BAT所载的批次指令。