Windows process info from Squeak

Valdas Bucinskas valdas.bucinskas at ipsistemos.lt
Wed Feb 1 07:32:41 UTC 2006


Thanks for the response.
For those who are interested, I have found another workaraound using
external utility Pslist (http://www.sysinternals.com/Utilities/PsList.html).
The code, returning how much RAM a Windows process is using, looks like this
(needs some refactoring though):
Prerequests: directory C:\Temp2 should exist, pslist.exe should be copied
into the directory that is listed in Windows Paths variable.

WindowsOS >> class
getInfo: aProcessName
	| path batch batchFile infoFromOutTxt numbers oc tmp filedir |
	path := 'C:\Temp2'.
	batch := 'pslist -m ' , aProcessName , ' >>' , path , '\out.txt'.
	filedir := FileDirectory new.
	filedir deleteFileNamed: path , '\out.txt' ifAbsent: nil.
	filedir deleteFileNamed: path , '\getProcessInfo.bat' ifAbsent: nil.
	[batchFile := (FileDirectory on: path)
				fileNamed: 'getProcessInfo.bat'.
	batchFile nextPutAll: batch]
		ensure: [batchFile close].
	Win32Shell new shellOpen: path , '\' , 'getProcessInfo.bat'.
	[(filedir fileExists: path , '\out.txt') not]
		whileTrue: [(Delay forSeconds: 0.1) wait].
	infoFromOutTxt := (FileDirectory new oldFileNamed: path , '\out.txt')
upToEnd.
	numbers := (infoFromOutTxt copyFrom: (infoFromOutTxt findString:
aProcessName startingAt: 1)
					+ aProcessName size to: infoFromOutTxt size) withBlanksTrimmed.
	oc := OrderedCollection new.
	tmp := ''.
	numbers
		do: [:e | e = $
				ifTrue: [oc add: tmp.
					tmp := '']
				ifFalse: [tmp := tmp asString , e asString]].
	oc
		removeAllSuchThat: [:e | e = ''].

	^ oc fourth asNumber

E.g.:
Running from workspace:
WindowsOS getInfo: 'explorer'

shows how much RAM is explorer.exe using

Best regards,
Valdas Bucinskas


-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org]On Behalf Of David T.
Lewis
Sent: Tuesday, January 31, 2006 2:54 PM
To: The general-purpose Squeak developers list
Subject: Re: Windows process info from Squeak


On Tue, Jan 31, 2006 at 02:34:25PM +0200, Valdas Bucinskas wrote:
> Hello
>
> Is there a way to get information about Windows XP processes from Squeak?
> Smth like how much RAM is the process using? What is PID of the process?
And
> so on.
> Any hints or workaraunds are very much welcome.

See OSProcess and OSProcessPlugin on Squeak Map.

There is an old version of the plugin (Win32OSProcessPlugin.dll)
included in the OSProcess distribution, but you'll need to build
your own from source with VMMaker if you want the latest. The old
one will give you pid, and the more recent OSPP also gives the
environment, the current working directory, main thread ID, etc.
For the other things you might be interested in (memory use),
you might want to just use one of the existing OSPP primitives
as a template and put in whatever you want.

One word of warning, the latest SVN sources for Windows VM have
a security related "feature" that will break some of the OSPP
file-related functions. Let me know if this is a problem for
you and I'll try to come up with some sort of workaround. It's
not something I'm working on at the moment though.

Dave





More information about the Squeak-dev mailing list