Segfault with win32ole, WMI and structs

Discussion in 'Ruby' started by Daniel Berger, May 23, 2004.

  1. 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
     
    Daniel Berger, May 23, 2004
    #1
    1. Advertising

  2. Dan,

    "Daniel Berger" <> 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
     
    Shashank Date, May 23, 2004
    #2
    1. Advertising

  3. Daniel Berger

    Jos Backus Guest

    On Sun, May 23, 2004 at 01:53:46PM +0900, Daniel Berger wrote:
    [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).

    --
    Jos Backus _/ _/_/_/ Sunnyvale, CA
    _/ _/ _/
    _/ _/_/_/
    _/ _/ _/ _/
    jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
     
    Jos Backus, May 23, 2004
    #3
  4. "Shashank Date" <> wrote in message news:<>...
    > Dan,
    >
    > "Daniel Berger" <> 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
     
    Daniel Berger, May 23, 2004
    #4
  5. Daniel Berger

    Jos Backus Guest

    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.


    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.

    --
    Jos Backus _/ _/_/_/ Sunnyvale, CA
    _/ _/ _/
    _/ _/_/_/
    _/ _/ _/ _/
    jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
     
    Jos Backus, May 24, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yonatan
    Replies:
    0
    Views:
    135
    yonatan
    Jan 6, 2004
  2. Daniel Berger

    Using Win32OLE, WMI and ExecMethod

    Daniel Berger, Jun 3, 2004, in forum: Ruby
    Replies:
    1
    Views:
    205
    Daniel Berger
    Jun 4, 2004
  3. Masaki Suketa
    Replies:
    4
    Views:
    421
    Dave Burt
    Mar 27, 2006
  4. Spike

    WMI and WIN32OLE issues

    Spike, Oct 26, 2006, in forum: Ruby
    Replies:
    0
    Views:
    99
    Spike
    Oct 26, 2006
  5. Barrie Hill

    win32ole and WMI question

    Barrie Hill, Jan 3, 2009, in forum: Ruby
    Replies:
    2
    Views:
    176
    Barrie Hill
    Jan 3, 2009
Loading...

Share This Page