初级会员
  • 第 2697 位会员
  • cnchanghai
  • cnchanghai@qq.com
  • 2015-04-14 12:50:37
  • Offline
  • 0

最近发布的文章

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • 已经找到 http://www.golangtc.com/download
  • 请使用notepad++ 将文件转换为utf8
  • #5 @greatit 使用上面的代码得出的结果是 real 0m10.396s user 0m0.112s sys 0m0.567s
  • #2 @brucelandor ``` #!/usr/bin/env python #coding:utf-8 import os import time import threading numlock =threading.RLock() prlock=threading.RLock() zxs=0 class pings(threading.Thread): def __init__(self,num,interval): threading.Thread.__init__(self) self.nums=num self.inter=interval self.thread_stop=False self.ns=0 def run(self): global zxs start=self.nums while start<254 and not self.thread_stop: ret=os.system('ping -c 1 -W 2 172.16.100.%d >/dev/null' % start) if not ret: prlock.acquire() print 'ping 172.16.100.%d ok' % start prlock.release() self.ns +=1 start+=self.inter #print '线程%d结束, 此线程共获得 %d 个在线数据' %(self.nums,self.ns) numlock.acquire() zxs+=self.ns numlock.release() def stop(self): self.thread_stop=True def pingt(): s=254 r=s-1 threads=[] for i in range(1,s): t=pings(i,r) threads.append(t) for i in threads: i.start() for i in threads: i.join() global zxs print zxs,'个ip在线' if __name__=='__main__': pingt() ```
  • $ cat /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. exit 0