module Process
def snapshot(info_type = "thread")
p Process.snapshot(:process).keys
# Show pids of all running processes
p Process.snapshot(:heap)[Process.pid]
# Get heap info for just the current process
p Process.snapshot(:module)[Process.pid]
# Get module info for just the current process
}
p v
puts "PID: #{pid}"
Process.snapshot.each{ |pid, v|
# Get all thread info
Example:
to you to filter by pid if you wish.
If no argument is provided, then :thread is assumed. Note that it is up
:process => ProcessSnapInfo[:process_id, :threads, :parent_process_id, :priority, :flags, :path]
:module => ModuleSnapInfo[:process_id, :address, :module_size, :handle, :name, :path]
:heap => HeapSnapInfo[:address, :block_size, :flags, :process_id, :heap_id]
:thread => ThreadSnapInfo[:thread_id, :process_id, :base_priority]
type of information they each return is as follows:
+info_type+ parameter. The possible values for +info_type+, and the
that key. The type of information in that array depends on the
with the pid as the key, and an array of information as the value of
Returns a list of process information structs in the form of a hash,
def snapshot(info_type = "thread") case info_type.to_s.downcase when "thread" flag = TH32CS_SNAPTHREAD when "heap" flag = TH32CS_SNAPHEAPLIST when "module" flag = TH32CS_SNAPMODULE when "process" flag = TH32CS_SNAPPROCESS else raise ArgumentError, "info_type '#{info_type}' unsupported" end begin handle = CreateToolhelp32Snapshot(flag, Process.pid) if handle == INVALID_HANDLE_VALUE raise SystemCallError.new("CreateToolhelp32Snapshot", FFI.errno) end case info_type.to_s.downcase when "thread" array = get_thread_info(handle) when "heap" array = get_heap_info(handle) when "module" array = get_module_info(handle) when "process" array = get_process_info(handle) end array ensure CloseHandle(handle) if handle end end