Re: getpid in Mac OS X [message #39785 is a reply to message #39773] |
Fri, 11 June 2004 14:56   |
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
|
|
|