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

Dan,

“Daniel Berger” djberg96@hotmail.com wrote in message

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

Did you try compiling it with the latest ruby source from CVS?
Just a hunch based on Jos Bckus’s experience (see ruby-talk 100087).

– shanko

Hi,

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.

I tested your code snippet with two Ruby versions.
With Ruby 1.8.1-13 it segfaulted. But with a Ruby
built with MinGW (the one that I’m currently using),
it didn’t segfault.

You can check out the output at:

Windows 2000
C:>ruby -v
ruby 1.8.2 (2004-05-19) [i386-mingw32]
C:>ruby -rwin32ole -e ‘p WIN32OLE::VERSION’
“0.5.5”

Besides that, I am useless :slight_smile:

Cheers,
Joao

···

Do you Yahoo!?
Yahoo! Domains – Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer

[snip]

Any ideas? Help appreciated.

Does it work with

ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ruby-1.8.2-20040519-i386-mswin32.zip

?

Problems (runtime termination errors) I was having with 1.8.1 on Windows
vanished when I switched to a 1.8.2/1.9.0 snapshot. The errors I saw were more
bizarre (e.g. removing a blank line in my source was in some cases
sufficient to crash the interpreter).

···

On Sun, May 23, 2004 at 01:53:46PM +0900, Daniel Berger wrote:


Jos Backus / /// Sunnyvale, CA
_/ _/ _/
/ ///
_/ _/ _/ /
jos at catnook.com // //
/ require ‘std/disclaimer’

Hi,

[snip]

Any ideas? Help appreciated.

Does it work with

ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ruby-1.8.2-20040519-i386-mswin32.zip

?

Problems (runtime termination errors) I was having
with 1.8.1 on Windows
vanished when I switched to a 1.8.2/1.9.0 snapshot.
The errors I saw were more
bizarre (e.g. removing a blank line in my source
was in some cases
sufficient to crash the interpreter).

This version is much better in comparision with Ruby
1.8.1-13.

I think I’m gonna keep it, thanks :slight_smile:

Cheers,
Joao

···

— Jos Backus jos@catnook.com wrote:

On Sun, May 23, 2004 at 01:53:46PM +0900, Daniel > Berger wrote:


Do you Yahoo!?
Yahoo! Domains – Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer

“Shashank Date” sdate@everestkc.net wrote in message news:2haqkpFb2e8sU1@uni-berlin.de

Dan,

“Daniel Berger” djberg96@hotmail.com wrote in message

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

Did you try compiling it with the latest ruby source from CVS?
Just a hunch based on Jos Bckus’s experience (see ruby-talk 100087).

– shanko

I tried compiling the latest stable snapshot and got a build error:

LINK : fatal error LNK1104: cannot open file “miniruby.exe”
NMAKE : fatal error U1077: ‘cl’ : return code ‘0x2’
Stop.
NMAKE : fatal error U1077: ‘.\miniruby.exe’ : return code ‘0x2’
Stop.

I’m giving up for now.

Dan

Hm, I successfully built Friday’s stable snapshot (ruby_1_8 branch iIrc) with
patches to the Windows installer (not to Ruby itself). I’ll double-check on
Monday. I’m in need of a more recent version since 1.8.1 is unfortunately too
buggy on Windows and I can’t afford to wait for the next official stable
release.

···

On Mon, May 24, 2004 at 06:13:45AM +0900, Daniel Berger wrote:

I tried compiling the latest stable snapshot and got a build error:

LINK : fatal error LNK1104: cannot open file “miniruby.exe”
NMAKE : fatal error U1077: ‘cl’ : return code ‘0x2’
Stop.
NMAKE : fatal error U1077: ‘.\miniruby.exe’ : return code ‘0x2’
Stop.


Jos Backus / /// Sunnyvale, CA
_/ _/ _/
/ ///
_/ _/ _/ /
jos at catnook.com // //
/ require ‘std/disclaimer’