Segfault with win32ole, WMI and structs

D

Daniel Berger

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
 
S

Shashank Date

Dan,

Daniel Berger said:
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
 
J

Jos Backus

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'
 
D

Daniel Berger

Shashank Date said:
Dan,



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
 
J

Jos Backus

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'
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top