Getting the IDL process identifier on Linux

Atle Borsholm showed me this technique for getting IDL’s process identifier (or process id or pid) on Linux (though it should work on any UNIX-based system):

IDL> pid = call_external('libc.so.6', 'getpid')
IDL> print, pid
       22468

I used this recently with pmap to get the memory map of an IDL process; I was curious to see how the OS reported the memory use of IDL plus the shared libraries it uses. For example, SPAWN a call to pmap:

IDL> spawn, 'pmap' + string(pid), pid_memory
IDL> print, ulong((strsplit(pid_memory[-1], /extract))[-1])
      137672

where pmap returns the total memory use in kilobytes, and compare this with the output from MEMORY, scaled to KB:

IDL> print, memory(/current) / 1024
        1029

The difference is that MEMORY (as noted on its Help page) doesn’t include memory used by shared libraries.

About these ads

About Mark

I solve scientific programming and visualization problems with IDL.
This entry was posted in language and tagged , , , , . Bookmark the permalink.

3 Responses to Getting the IDL process identifier on Linux

  1. This worked for me on Mac OS X:

    IDL> print, call_external('libc.dylib', 'getpid')
           44495

    I also have a MG_PID routine in mglib that returns the PID using the IDL API which is more cross-platform.

  2. Mark says:

    Jim Pendleton also has a technique for Windows:

    IDL> ProcessID = StrTrim(Call_External('kernel32.dll', 'GetCurrentProcessId'), 2)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s