comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: getpid in Mac OS X
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: getpid in Mac OS X [message #39765] Mon, 14 June 2004 12:43 Go to next message
MKatz843 is currently offline  MKatz843
Messages: 98
Registered: March 2002
Member
Miguel Angel Cordoba wrote:
> Thank you,
> but this solution only works if only one IDL process is running. In my
> case there are 4 processes and I need all the PID's.

OK, so all that takes is a few strokes of the pen...
The function below returns a list. Below the code snippet is an
example run.
Note that this is Darwin (OS X) specific. It wouldn't take much to
make it work on Linux.

---------code---------
function idl_pids
pid = -1 ;--- default value appropriate for Mac, PC

if (!version.os EQ 'darwin') then begin
spawn, 'ps', list
print, '----------'
print, list
print, '----------'
w = where((strpos(list, 'Applications') GT 0) $
and (strpos(list, 'idl') GT 0), count)
if (count LT 1) then begin
print, 'idl_pids error: no valid jobs'
return, -1
endif
pid = lonarr(count)
for i=0,count-1 do $
pid(i) = long( (strsplit(list(w(i)), ' ', /EXTRACT))(0) )
endif

return, pid
end
------ end of code ------

IDL> print, idl_pids()
----------
PID TT STAT TIME COMMAND 11879 std Ss 0:00.06 -csh
11898 std S+ 0:03.54 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
11947 std S+ 0:00.02 tcsh -c ps 11885 p2 Ss 0:00.06 -csh
11901 p2 S+ 0:03.36 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
11891 p3 Ss 0:00.07 -csh
11894 p3 S+ 0:03.75 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
----------
11898 11901 11894

Get rid of the print statements if you like.
M. Katz
Re: getpid in Mac Os X [message #39771 is a reply to message #39765] Mon, 14 June 2004 06:29 Go to previous messageGo to next message
Miguel Angel Cordoba is currently offline  Miguel Angel Cordoba
Messages: 13
Registered: April 2004
Junior Member
Thank you Mike,
probably this is the problem.Probably I'll create a dlm with then calls to
the getpid() function.

Regards.

Michael Wallace wrote:

>> IDL>pid=CALL_EXTERNAL('/usr/lib/libc.dylib','getpid')
>> % CALL_EXTERNAL: Error loading sharable exectuble.
>> Symbol: getpid, FILE=/usr/lib/libc.dylib
>> not a Mach-O MH-BUNDLE file type
>
>
> I am no OS X expert nor a CALL_EXTERNAL expert, but I nevertheless
> have a theory about what's happening. You might want to double-check
> this theory with RSI to make sure that I'm not way off base.
>
> It seems that IDL is looking for a file with the MH_BUNDLE file type
> flag. MH_BUNDLE is typically used by code which is loaded at runtime.
> The file extension on such files is .bundle.
>
> The /usr/lib/libc.dylib has MH_DYLIB as the file type flag. MH_DYLIB
> is meant for dynamic shared libraries. I'm not sure why IDL can't
> load this file at runtime as it can on Linux, but my guess is that the
> library is only "shared" in the linker sense of the term rather than
> the executable sense. Keep in mind this is just a guess -- I don't
> know enough of the internal workings of OS X libraries to say for sure.
>
> Whatever the case, a better solution to the problem would be to create
> a little DLM as an interface into the libc library rather than trying
> to call commands out of the library directly. On OS X, you could
> create a bundle file which calls the getpid() function in libc. IDL
> shouldn't have a problem loading this bundle.
>
> -Mike


--
_________________________________________________________
Miguel Angel Cordoba
---------------------------------------------------------
Grup de Recerca Aplicada en Hidrometeorologia (GRAHI-UPC)
http://www.grahi.upc.es
---------------------------------------------------------
Centre membre de la Xarxa d'Innovacio Tecnologica XIT
http://www.cidem.com/xarxait
_________________________________________________________
Re: getpid in Mac OS X [message #39773 is a reply to message #39771] Mon, 14 June 2004 06:07 Go to previous messageGo to next message
Miguel Angel Cordoba is currently offline  Miguel Angel Cordoba
Messages: 13
Registered: April 2004
Junior Member
Thank you,
but this solution only works if only one IDL process is running. In my
case there are 4 processes and I need all the PID's.

Regards.

M. Katz wrote:

> Here's a possible solution. It's more of a stopgap than anything
> elegant....
> When you spawn, 'ps' you get output that looks like this
>
> PID TT STAT TIME COMMAND 486 std Ss 0:00.27 -csh
> 614 std S+ 0:23.30 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
> 734 std R+ 0:00.05 tcsh -c ps
>
> So we'll use that output to look for the corrent line, and identify
> the ID as 614 in this case
>
> === code snippet ===
> pid = -1 ;--- default value means unknown PID
>
> if (!version.os EQ 'darwin') then begin ;--- we're on a Mac
> spawn, 'ps', list ;--- this returns a long list of processes
> ;--- My IDL app lives in /Applications, so here I'm looking for
> a
> ; line that has "/Applications" and "idl" in the line.
> ; If your IDL app lives somewhere else, change this to
> something else
> ;--- Find which process might be the right one.
> w = where((strpos(list, 'Applications') GT 0) and (strpos(list,
> 'idl') GT 0), count)
> if (count GT 0) then $
> pid = long( (strsplit(list(w), ' ', /EXTRACT))(0) )
> endif
> === end of code snippet ===
>
> Miguel Angel Cordoba <cordoba_nospam@grahi.upc.es> wrote in message news:<40C9B961.8000605@grahi.upc.es>...
>
>
>> Hi,
>> I want to get the process identification (pid) of my IDL. In
>> Linux I get the pid calling:
>>
>> pid=CALL_EXTERNAL('/usr/lib/i686/libc.so.6','getpid')
>>
>> but this library doesn't exist in Mac Os X. I had probed with
>> the '/usr/lib/libc.dylib' but didn't work. Any ideas?
>>
>> IDL>pid=CALL_EXTERNAL('/usr/lib/libc.dylib','getpid')
>> % CALL_EXTERNAL: Error loading sharable exectuble.
>> Symbol: getpid, FILE=/usr/lib/libc.dylib
>> not a Mach-O MH-BUNDLE file type
>>
>> Thanks a lot.
>>
>> --
>> _________________________________________________________
>> Miguel Angel Cordoba
>>
>>

--
_________________________________________________________
Miguel Angel Cordoba mailto:cordoba@grahi.upc.es
Tel. +34 934 017 371
Fax. +34 934 054 194
---------------------------------------------------------
Grup de Recerca Aplicada en Hidrometeorologia (GRAHI-UPC)
http://www.grahi.upc.es
---------------------------------------------------------
Centre membre de la Xarxa d'Innovacio Tecnologica XIT
http://www.cidem.com/xarxait
_________________________________________________________
Re: getpid in Mac OS X [message #39785 is a reply to message #39773] Fri, 11 June 2004 14:56 Go to previous messageGo to next message
MKatz843 is currently offline  MKatz843
Messages: 98
Registered: March 2002
Member
Here's a possible solution. It's more of a stopgap than anything
elegant....
When you spawn, 'ps' you get output that looks like this

PID TT STAT TIME COMMAND 486 std Ss 0:00.27 -csh
614 std S+ 0:23.30 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
734 std R+ 0:00.05 tcsh -c ps

So we'll use that output to look for the corrent line, and identify
the ID as 614 in this case

=== code snippet ===
pid = -1 ;--- default value means unknown PID

if (!version.os EQ 'darwin') then begin ;--- we're on a Mac
spawn, 'ps', list ;--- this returns a long list of processes
;--- My IDL app lives in /Applications, so here I'm looking for
a
; line that has "/Applications" and "idl" in the line.
; If your IDL app lives somewhere else, change this to
something else
;--- Find which process might be the right one.
w = where((strpos(list, 'Applications') GT 0) and (strpos(list,
'idl') GT 0), count)
if (count GT 0) then $
pid = long( (strsplit(list(w), ' ', /EXTRACT))(0) )
endif
=== end of code snippet ===

Miguel Angel Cordoba <cordoba_nospam@grahi.upc.es> wrote in message news:<40C9B961.8000605@grahi.upc.es>...
> Hi,
> I want to get the process identification (pid) of my IDL. In
> Linux I get the pid calling:
>
> pid=CALL_EXTERNAL('/usr/lib/i686/libc.so.6','getpid')
>
> but this library doesn't exist in Mac Os X. I had probed with
> the '/usr/lib/libc.dylib' but didn't work. Any ideas?
>
> IDL>pid=CALL_EXTERNAL('/usr/lib/libc.dylib','getpid')
> % CALL_EXTERNAL: Error loading sharable exectuble.
> Symbol: getpid, FILE=/usr/lib/libc.dylib
> not a Mach-O MH-BUNDLE file type
>
> Thanks a lot.
>
> --
> _________________________________________________________
> Miguel Angel Cordoba
Re: getpid in Mac Os X [message #39788 is a reply to message #39785] Fri, 11 June 2004 08:36 Go to previous messageGo to next message
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
> IDL>pid=CALL_EXTERNAL('/usr/lib/libc.dylib','getpid')
> % CALL_EXTERNAL: Error loading sharable exectuble.
> Symbol: getpid, FILE=/usr/lib/libc.dylib
> not a Mach-O MH-BUNDLE file type

I am no OS X expert nor a CALL_EXTERNAL expert, but I nevertheless have
a theory about what's happening. You might want to double-check this
theory with RSI to make sure that I'm not way off base.

It seems that IDL is looking for a file with the MH_BUNDLE file type
flag. MH_BUNDLE is typically used by code which is loaded at runtime.
The file extension on such files is .bundle.

The /usr/lib/libc.dylib has MH_DYLIB as the file type flag. MH_DYLIB is
meant for dynamic shared libraries. I'm not sure why IDL can't load
this file at runtime as it can on Linux, but my guess is that the
library is only "shared" in the linker sense of the term rather than the
executable sense. Keep in mind this is just a guess -- I don't know
enough of the internal workings of OS X libraries to say for sure.

Whatever the case, a better solution to the problem would be to create a
little DLM as an interface into the libc library rather than trying to
call commands out of the library directly. On OS X, you could create a
bundle file which calls the getpid() function in libc. IDL shouldn't
have a problem loading this bundle.

-Mike
Re: getpid in Mac OS X [message #39900 is a reply to message #39765] Tue, 15 June 2004 02:22 Go to previous message
Miguel Angel Cordoba is currently offline  Miguel Angel Cordoba
Messages: 13
Registered: April 2004
Junior Member
Thank you,
but the problem is that I need the PID off the process. If I execute three
processes all off them needs his PID and with 'ps' list I think that
it's not possible.
With the 'ps' method I can find the three PID's but I can't know who is his
owner.
With the "call_external" method in all the programs I execute this to
get the
PID off the process.

SOLARIS:
my_pid=CALL_EXTERNAL('/lib/sparcv9/libc.so','getpid')

LINUX
my_pdi=CALL_EXTERNAL('/lib/i686/libc.so.6','getpid')

then the problem in Mac Os X is the error:

IDL>pid=CALL_EXTERNAL('/usr/lib/libc.dylib','getpid')
% CALL_EXTERNAL: Error loading sharable exectuble.
Symbol: getpid, FILE=/usr/lib/libc.dylib
not a Mach-O MH-BUNDLE file type

Any ideas?. Thank you.

M. Katz wrote:

> Miguel Angel Cordoba wrote:
>
>
>> Thank you,
>> but this solution only works if only one IDL process is running. In my
>> case there are 4 processes and I need all the PID's.
>>
>>
>
> OK, so all that takes is a few strokes of the pen...
> The function below returns a list. Below the code snippet is an
> example run.
> Note that this is Darwin (OS X) specific. It wouldn't take much to
> make it work on Linux.
>
> ---------code---------
> function idl_pids
> pid = -1 ;--- default value appropriate for Mac, PC
>
> if (!version.os EQ 'darwin') then begin
> spawn, 'ps', list
> print, '----------'
> print, list
> print, '----------'
> w = where((strpos(list, 'Applications') GT 0) $
> and (strpos(list, 'idl') GT 0), count)
> if (count LT 1) then begin
> print, 'idl_pids error: no valid jobs'
> return, -1
> endif
> pid = lonarr(count)
> for i=0,count-1 do $
> pid(i) = long( (strsplit(list(w(i)), ' ', /EXTRACT))(0) )
> endif
>
> return, pid
> end
> ------ end of code ------
>
> IDL> print, idl_pids()
> ----------
> PID TT STAT TIME COMMAND 11879 std Ss 0:00.06 -csh
> 11898 std S+ 0:03.54 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
> 11947 std S+ 0:00.02 tcsh -c ps 11885 p2 Ss 0:00.06 -csh
> 11901 p2 S+ 0:03.36 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
> 11891 p3 Ss 0:00.07 -csh
> 11894 p3 S+ 0:03.75 /Applications/idl_6.0/bin/bin.darwin.ppc/idl
> ----------
> 11898 11901 11894
>
> Get rid of the print statements if you like.
> M. Katz
>
>

--
_________________________________________________________
Miguel Angel Cordoba
---------------------------------------------------------
Grup de Recerca Aplicada en Hidrometeorologia (GRAHI-UPC)
http://www.grahi.upc.es
---------------------------------------------------------
Centre membre de la Xarxa d'Innovacio Tecnologica XIT
http://www.cidem.com/xarxait
_________________________________________________________
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: dates transformation
Next Topic: Re: dates transformation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 16:30:57 PDT 2025

Total time taken to generate the page: 1.44057 seconds