Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

memory in interix

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Tools Discussion Forum >> memory in interix Page: [1]
Login
Message << Older Topic   Newer Topic >>
memory in interix - Nov. 19, '04, 5:38:10 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
Is there any tool to report the free and avauilable and total memory for interix? Just the same information that the top.exe displays? Are they available somewhere in interix or just in win32?
Post #: 1
RE: memory in interix - Nov. 19, '04, 8:04:01 PM   
markfunk

 

Posts: 623
Joined: Mar. 31, '03,
Status: offline
This question doesn't make sense.

Interix has no control over physical memory
and the Interix environment does not manage physical memory in any way.
Interix is just another Window's OS process.
All physical memory control is handled by the OS kernel.

So this information is not part of the Interix environment.
Just the Window's/Win32 environment.

(in reply to cortez_)
Post #: 2
RE: memory in interix - Nov. 20, '04, 3:35:21 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
As far as I have understood the structure of the windows OS the Interix and Win32 are on the same level beeing the subsystems (At kleast MS advertises they are). And memory is managed by the kernel which lies beneath the subsystems. So the question makes sense because if the subsystems are more or less equal they both should have APIs to check how much free memory is available. Otherwise how can a programmer determine how much memory can the process allocate? Do I miss something here?

(in reply to markfunk)
Post #: 3
RE: memory in interix - Nov. 20, '04, 5:50:37 PM   
ndornbrook

 

Posts: 8
Joined: Nov. 7, '04,
Status: offline
Hey, Cortez!

I compiled the gnu top and it works fine under Interix. Will this meet your needs?

(in reply to cortez_)
Post #: 4
RE: memory in interix - Nov. 20, '04, 7:06:35 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
The gnu top was the ever desired and never reached port I've been approaching. Altough that doesn't answer directly the question posted in this thread - it does answer a question I have asked an age ago! YES! Would be great if you could upload it into the ftp, please! Maybe you can even package it. And anyway can you post here some tips on how did you get it running? This tool might be very usefull for me.

< Message edited by cortez_ -- Nov. 20, '04, 7:08:07 PM >

(in reply to ndornbrook)
Post #: 5
RE: memory in interix - Nov. 20, '04, 10:27:42 PM   
markfunk

 

Posts: 623
Joined: Mar. 31, '03,
Status: offline
Yes both Interix and Win32 are Window's subsystems. But Win32 is a mostly a thin veneer to the Window's kernel services. Some Win32 api's are very similar to the kernel interfaces and some api's have been restructured to give a better presentation to the programmer.

The memory that 'top' returns is the system physical memory, which is a
resource handled by the Window's kernel.

Interix is a UNIX environment subsytem. Physical memory is not something this environment requires. Thus, no api's were written
to return physical memory usage. While potentially useful for system admin,
the guidelines used by Softway were that system admin is normally performed
via the Win32 subsystem so physical memory api's were not ever a priority.

In terms of process memory - this is virtual memory not physical memory.
Interix provides the api's to deal with virtual memory allocation. Also the
binary executable image also contains information about how
much memory a process pre-allocates when the program is executed.
These are parameters set at compile/link time. The total virtual
memory allocation per process on x86 hardware is normally limited to 2Gig.

(in reply to cortez_)
Post #: 6
RE: memory in interix - Nov. 21, '04, 3:06:56 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
I think the assumption that the system should be administered from within win32 only is wrong. Thera are many people (including myseld) that are willing to at east be able to monitor system resources from within interix and want to do it remotely.

(in reply to markfunk)
Post #: 7
RE: memory in interix - Nov. 21, '04, 5:16:48 AM   
ndornbrook

 

Posts: 8
Joined: Nov. 7, '04,
Status: offline
Hey, Cortez, I was telling a big porkie pie there; I thought I was getting top functionality from the GNU coreutils package, but I'm getting it from top.exe.

Okay, I'm headed over to SF to get the procps source and see what I can do.

(in reply to cortez_)
Post #: 8
RE: memory in interix - Nov. 21, '04, 9:17:32 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
Another think to do that I've been thinking about is to do the undoable and connect to the win32 from interix through some IPC mechanism that is allowed. I'm not good at windows APIs but it probably would be possible to write some module that would work in win32 and present the information that we are interested in through some form of interface. Than the client programs or scripts could use them just as the /proc filesystem is beeing used. It might even be script a wrapper around some win32 command.

Anyway I think that lack of such information in interix is a huge gap. BTW - where the ps takes it's process info from??

(in reply to ndornbrook)
Post #: 9
RE: memory in interix - Nov. 21, '04, 5:02:29 PM   
Rodney

 

Posts: 2949
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
I'm not surprised that ndornbrook found out that the top was top.exe.
The underlying API's are not present for a Unix top to currently be done.
I've look at it before (so yea might as well save some time trying).

For cortez's question:
A common thing to do is make a command line Win32 utility and make sure it's
output goes to stdout only. Then you can run this Win32-app via a popen()
and gather the information and parse it as you like.

The ps utility gets it's information from the /proc filesystem.
The /proc filesystem is special as it's generated by Interix on-the-fly
as processes come and go. The information is gleened from tables internal
to the Interix subsystem and from information from the NT/Windows kernel.

< Message edited by Rodney -- Nov. 21, '04, 5:03:08 PM >

(in reply to cortez_)
Post #: 10
RE: memory in interix - Nov. 22, '04, 5:03:34 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
so the easiest way is to write two modules. The win32 module will retrieve the information from win32 API and thed export it to stdout

The Interix module will execute the win32 module using popen() /*will the runwin32 command be neccesary to be used? I suupose it will have to be specified in the execution of popen() */
then it will parse from stdin the and format the output to the stdout

To make it clear the only way to access the win32 API is to use the IPC (pipes, filesystem, shared memory) right? Could you maybe explain a little how shared memory works?

And where the complete list of interix APIs (better said "system calls") can be found? (Just in order to evade doing the same job twice)

< Message edited by cortez_ -- Nov. 22, '04, 5:08:17 PM >

(in reply to Rodney)
Post #: 11
RE: memory in interix - Nov. 23, '04, 1:49:07 AM   
Rodney

 

Posts: 2949
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
The runwin32 isn't need. It's really a wrapper script.
You'll want to use the unixpath2win(2) {the API not the utility} if you need
to convert any pathname information for the args to the Win32 program.
The easiest thing is usually try and have the information in the args to the
Win32 program. You can used shared memory, pipes, sockets and the filesystem
to transfer data too. But I'd follow the principal of the simpler it can be
kept the less debugging you will have to do (particularly if there is a need
for passing messages back and forth).

Shared memory:
It's pretty straight-forward. When using it with a Interix/Win32 setup you can
use the mmap() and friends API's for the Interix side. The reason you need to
use mmap() is the mechanism used (by way of Kernel calls) has matching functionality
on the Win32 side. The space is created and backed by a file on the file system.
The memory is sync'd immediately amongst the processes sharing this memory. You do
not need to have the memory flushed to the filesystem to share/use it. There are examples
of code on the MSDN web site on how to write Win32 memory mapped code. The tricky part is that
there are no shared semaphores (or similer signalling mechanism) to let "other other side"
know when it can safely read/write to a zone of memory. You can do a spin test but that sucks
the CPU time up. You can send a small signal byte through a socket et al. There are speed/size
trade-off's here. It's best if it's a large chunk of memory. "Small" chunks of memory are likely
more easily just sent back and forth with pipes or sockets.
The Win32 side has two memory mapped types. You must use the one that you give a filename to.
The general WIn32 API order is OpenFile(), CreateFileMapping(), MapViewOfFile(), UnmapViewOfFile().
Note that even if you have the Interix side create the file you still need on the Win32 side to
call CreateFileMapping(). On MSDN there are a couple of examples that don't use CFM() -- ignore them
and follow the examples that use CFM().

As for API's: the vast majority of API's have prototypes in the header files (yeah, there are a few
missing). So you can grep through the header files (don't forget <interix/...>). You can use the
man pages too. Get the man and catman packages and then regenerate the whatis.db files
with the makewhatis utility. You can then use apropos and whatis to help you
find information on the functionality you're looking for. You can also use nm on the libraries
and do a grep " T " to distill out the functions from each library. You can always ask in the
Forum too.

< Message edited by Rodney -- Nov. 23, '04, 1:51:17 AM >

(in reply to cortez_)
Post #: 12
RE: memory in interix - Nov. 23, '04, 7:54:57 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
There's an API GlobalMemoryStatus which returns almost all the neccesary info for free command. Obviously I'll write an win32 module to extract that, but I'm just wandering what would be better:
1. to write a shell script wrapping the win32 module and formatting the output, or
2. writing the wrapper in C ?

What would be faster and more bug free, more elegant anyway what would be better?

I'm just wondering if it would be of any use to make these win32 API available to interix environment this way.

< Message edited by cortez_ -- Nov. 23, '04, 7:56:36 AM >

(in reply to Rodney)
Post #: 13
RE: memory in interix - Nov. 23, '04, 8:47:31 AM   
markfunk

 

Posts: 623
Joined: Mar. 31, '03,
Status: offline
Use the GlobalMemoryStatusEx() api.
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatusex.asp
for a little program that will print out the information to stdout.
Modify it to suit your needs.

It easy enough to build: wcc meminfo.c
(note, wcc requires the Microsoft C compiler)

(in reply to cortez_)
Post #: 14
RE: memory in interix - Nov. 23, '04, 4:15:17 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
Is the difference between these APIs only in returning the exit status?

I'll see how that works and write what happens, anyway tell me might it be usefull to export some win APIs to interix in this way?

(in reply to markfunk)
Post #: 15
RE: memory in interix - Nov. 25, '04, 4:41:00 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
I have identified several variables that are used in the unix code of free. These are:

unsigned long kb_main_shared;

unsigned long kb_main_buffers;
unsigned long kb_main_cached;
unsigned long kb_main_free;
unsigned long kb_main_total;
unsigned long kb_swap_free;
unsigned long kb_swap_total;

unsigned long kb_high_free;
unsigned long kb_high_total;
unsigned long kb_low_free;
unsigned long kb_low_total;

unsigned long kb_swap_used;
unsigned long kb_main_used;

The MEMORYSTATUSEX returns as follows:
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;

Therefore I have some doubts:
First the data types - won't they conflict if I read the output in DWORDLONG into unsigned long?

Second - I suppose I will have to recount them as MEMORYSTATUSEX contains values in bytes, and unix variables in kylobytes. So I shal divide them by 1024 right?

Third the counting. I assume I can match them in such a way:
kb_main_total = ullTotalPhys/1024
kb_main_free = ullAvailPhys/1024


kb_main_used = kb_main_total - kb_main_free
kb_swap_total = ullTotalPageFile/1024
kb_swap_free = ullAvailPageFile/1024

kb_swap_used = kb_swap_total - kb_swap_free


But what about matching the:
ullTotalVirtual;
ullAvailVirtual;
ullAvailExtendedVirtual;

And:
kb_main_shared;
kb_main_buffers;
kb_main_cached;
kb_high_free;
kb_high_total;
kb_low_free;
kb_low_total;


Anybody helps?

(in reply to cortez_)
Post #: 16
RE: memory in interix - Nov. 26, '04, 2:55:29 AM   
Rodney

 

Posts: 2949
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
It's up to you what you want to do with the values.
Most (if not all) of the Win32 names for various data types map to standard names.
In fact the bit and byte orders will match too because it's on the same machine.

If you want to change bytes to kilobytes then yes it's divide by 1024.

(in reply to cortez_)
Post #: 17
RE: memory in interix - Nov. 26, '04, 5:47:36 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
Ok.

The win32module exportw the values of the Win32 API to the stdout and the interix module retrieves them through stdin. Seems to work fine.

The program works fine, and has a look anf feel of linuxish free but where the hell get these values from:
kb_main_shared;
kb_main_buffers;
kb_main_cached;
kb_high_free;
kb_high_total;
kb_low_free;
kb_low_total;

? Does the win32 kernel give these info anywhere? Or shall I just forget about them?

I will use bit shifting instead of using div() to keep the code smaller and nicer.

(in reply to Rodney)
Post #: 18
RE: memory in interix - Nov. 26, '04, 3:00:34 PM   
Rodney

 

Posts: 2949
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
> ? Does the win32 kernel give these info anywhere? Or shall I just forget about them?

I'd run with what you have to first see that things are working okay.
I don't know the answer to your first question as I haven't looked.
But look at what top.exe provides (or doesn't) and that might be hint
for what can/cannot be available.

(in reply to cortez_)
Post #: 19
RE: memory in interix - Nov. 26, '04, 4:37:04 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
I'll upload you the two binaries and source codes to the ftp. Anyway, The values I receive are the same that top.exe reports. The only thing that I know that exists and I can't find is the "cached" value from top.exe that I suppose will (If found in some other win32 API) map to kb_main_cached;

I suppose I will probably give up the migh and low memory values. The shared memory seems to be obsolete for most of linux dirstos and therefore usless (so probably doesn't exist in win32 world). But the buffers value is a mystery to me.

Anyway I'll keep diggng.

(in reply to Rodney)
Post #: 20
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Tools Discussion Forum >> memory in interix Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.078