All pastes #142743 Raw Edit

Something

public text v1 · immutable
#142743 ·published 2006-08-21 17:31 UTC
rendered paste body
        def Task.list
                print "\033[0;36;40m*\033[0mList tasks for: "
                cpuset = gets.strip
                apidlist = Array.new
                if cpuset == ""
                        puts "\033[0;36;40m*\033[0mInvalid input"
                end
                if !FileTest.exist?($cpuset_dir + "/" + cpuset + "/tasks")
                        puts "\033[0;36;40m*\033[0mI'm sorry that cpuset doesn't exist."
                else
                        puts "\033[0;36;40m*\033[0mFound cpuset, getting list. This may take a moment."
                        tfile = File.new($cpuset_dir + "/" + cpuset + "/tasks", "r")
                        while !tfile.eof
                                tfile.each {|line| apidlist.push(line.strip)}
                        end
                        pid_stat = ""
                        puts "\033[0;36;40m*\033[0mTask list for... #{cpuset}"
                        puts "PID  \033[0;36;40m-\033[0m  Name  \033[0;36;40m-\033[0m  CPU"
                        apidlist.each {|i| Task.getinfo(i)}
                end
        end
        def Task.getinfo(pid)
                pid_stat = ""
                pidFile = File.new($proc_dir + "/" + pid + "/stat", "r")
                while !pidFile.eof
                        pidFile.each {|line| pid_stat = line}
                end
                pidFile.close
                pidName = pid_stat.slice(pid_stat.index("("), (pid_stat.index(")") - pid_stat.index("(")) + 1)
                pidLine = pid_stat.slice(0, pid_stat.rindex(" ") - 1)
                pidLine = pidLine.slice(0, pidLine.rindex(" "))
                pidcpu = pidLine.slice(-1, pidLine.length)
                puts "#{pid} \033[0;36;40m-\033[0m #{pidName} \033[0;36;40m-\033[0m #{pidcpu}"
        end