From: djberg96@... (Daniel Berger) Date: 2004-05-23T13:53:46+09:00 Subject: Segfault with win32ole, WMI and structs Hi all, Ruby 1.8.1-13 Windows 2000 Win32OLE 0.5.5 I'm trying to build a pure Ruby version of sys-proctable for Windows using the WMI interface. The code below gives me a segfault if I use the block form, but not if I use the non-block form. Also, if I remove the 'private_page_count' from the @fields array and the 'proc.PrivatePageCount' in the struct below, it works fine. Experiments seem to show that it has problems with members that are converted from UINT64's, but I can't be 100% certain because my results have been sporadic, but trying to add any of the remaining UINT64 bit fields that I've left out (WriteOperationCount, WriteTransferCount, etc) causes a segfault. Various attempts at calling GC.start manually in specific places did not work. For a list of the fields and their types see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_process.asp Any ideas? Help appreciated. Dan # wmi.rb require "win32ole" module Sys class ProcTable @host = '.' # Default to localhost @fields = %w/ caption creation_class_name creation_date cs_creation_class_name cs_name description executable_path execution_state handle hanle_count install_date kernel_mode_time maximum_working_set_size minimum_working_set_size name os_creation_class_name os_name other_operation_count other_transfer_count page_faults page_file_usage peak_virtual_size ppid peak_working_set_size priority private_page_count pid quota_non_paged_pool_usage quota_paged_pool_usage quota_peak_non_paged_pool_usage quota_non_paged_pool_usage session_id termination_date thread_count windows_version / ProcTableStruct = Struct.new("ProcTableStruct",*@fields) def self.fields @fields end def self.host @host end def self.host=(host) @host = host end def self.ps a = [] connect_string = 'winmgmts://' + self.host mgmt = WIN32OLE.connect(connect_string) mgmt.InstancesOf("win32_process").each{ |proc| s = ProcTableStruct.new( proc.Caption, proc.CreationClassName, proc.CreationDate, proc.CSCreationClassName, proc.CSName, proc.Description, proc.ExecutablePath, proc.ExecutionState, proc.Handle, proc.HandleCount, proc.InstallDate, proc.KernelModeTime, proc.MaximumWorkingSetSize, proc.MinimumWorkingSetSize, proc.Name, proc.OSCreationClassName, proc.OSName, proc.OtherOperationCount, proc.OtherTransferCount, proc.PageFaults, proc.PageFileUsage, proc.ParentProcessId, proc.PeakVirtualSize, proc.PeakWorkingSetSize, proc.Priority, proc.PrivatePageCount, proc.ProcessId, proc.QuotaNonPagedPoolUsage, proc.QuotaPagedPoolUsage, proc.QuotaPeakNonPagedPoolUsage, proc.QuotaPeakPagedPoolUsage, proc.SessionId, proc.TerminationDate, proc.ThreadCount, proc.WindowsVersion ) if block_given? yield s else a.push(s) end } return a unless block_given? end end end if $0 == __FILE__ include Sys # This segfaults ProcTable.ps{ |pstruct| p pstruct } a = ProcTable.ps # this works fine # verify fields to struct count p ProcTable::ProcTableStruct.members.length p ProcTable.fields.length end