#!/usr/bin/env python
import select
#导入select模块
BLKSIZE=8192
def readwrite(fromfd,tofd):
readbuf = fromfd.read(BLKSIZE)
if readbuf:
tofd.write(readbuf)
tofd.flush()
return len(readbuf)
def copy2file(fromfd1,tofd1,fromfd2,tofd2):
''' using select to choice fds'''
totalbytes=0
if not (fromfd1 or fromfd2 or tofd1 or tofd2) :
#检查所有文件描述符是否合法
return 0
while True:
#开始利用select对输入所有输入的文件描述符进行监视
rs,ws,es = select.select([fromfd1,fromfd2],[],[])
for r in rs:
if r is fromfd1:
#当第一个文件描述符可读时,读入数据
bytesread = readwrite(fromfd1,tofd1)
totalbytes += bytesread
if r is fromfd2:
bytesread = readwrite(fromfd2,tofd2)
totalbytes += bytesread
if (bytesread <= 0):
break
return totalbytes
def main():
fromfd1 = open("/etc/fstab","r")
fromfd2 = open("/etc/passwd","r")
tofd1 = open("/root/fstab","w+")
tofd2 = open("/root/passwd","w+")
totalbytes = copy2file(fromfd1,tofd1,fromfd2,tofd2)
print "Number of bytes copied %d\n" % totalbytes
return 0
if __name__=="__main__":
main()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有