Getting the Process ID (PID) from with OpenEdge

Posted by damoon on 03-Jan-2011 14:16

Hi All,

     Does anyone know a way that I could start a process within a Progress ABL session and be able to obtain the PID?   I'm running on a unix box.

Thanks,

    Andre

All Replies

Posted by maximmonin on 04-Jan-2011 01:50

Check _Connect table field _Connect-pid

Posted by damoon on 04-Jan-2011 07:30

  Maxim,

     The _connect table shows me the pid  . However, If I have multiple sessions being started sequentially. How can I determine which pid is assigned to each session?  I'm launching an mbpro session and is there an attribute of parameter that I can use to determine which pid is assigned towhich session.

Thanks,

    Andre

Posted by maximmonin on 04-Jan-2011 07:52

we use code like:

  FOR EACH _Connect NO-LOCK WHERE _Connect-Usr NE ?

                              AND

    (_Connect-Type EQ "REMC"  OR _Connect-Type EQ "SELF" or _Connect-Type EQ "0" )

                         BREAK BY _Connect-Usr:

    IF _Connect-PID = ? THEN

      NEXT.

    IF _Connect-Type EQ "SELF" OR  _Connect-Device NE "" THEN

      ASSIGN cClientType = "4GL Client".

    ELSE

      ASSIGN cClientType = "SQL-92 Client".

    FIND FIRST users WHERE users.sys-name = _Connect-Name NO-LOCK NO-ERROR.

    IF AVAILABLE users THEN

    DO:

      user-name = users.Name.

      rid-user  = users.rid-user.

    END.

    ELSE

      user-name = _Connect-Name.

    CREATE work-users1.

    ASSIGN

      work-users1.logininfo = string (_Connect-time)

      work-users1.tty-name  = _Connect-Device

      work-users1.user-name = user-name

      work-users1.rid-user  = rid-user

      work-users1.pid       = _Connect-PID

      work-users1.id-proc   = _Connect-Usr.

/*    DISPLAY _Connect.*/

  END.

to identify users and tty/pids,
to display working users and kill sessions if nessesary.

Also you can use _MyConnection table to identify current session.

Posted by damoon on 04-Jan-2011 08:20

Maxim,

This is just what I needed.   Thanks for your help..

    Andre

Posted by abevoelker on 05-Jan-2011 13:19

You can use mpro -b with an & at the end instead of mbpro, as it is exactly the same command (cf. "Startup Command and Parameter Reference").

So, for example, if you were doing

mbpro -p MyProgram.p

Change it to

mpro -b -p MyProgram.p &

And now, thanks to Unix, you can access the PID of the most recent process sent to background by using the $! variable.

So if you wanted to save the PID using this method, do something like this:

PIDFILE=$HOME/myprogram.pid

mpro -b -p MyProgram.p &

echo $! > $PIDFILE

Posted by gus on 06-Jan-2011 12:41

Another way:

procedure getpid external 'libc.so' cdecl.

  define return parameter pid as long no-undo.

end.

def var p as int no-undo.

run getpid (output p).

Posted by ChUIMonster on 08-Feb-2011 09:06

Gus,

I must be having a bad day:

Could not open Dynamic Library: libc.so (8013)
DLL Error : /usr/lib64/libc.so: invalid ELF header (8014)

Could not load DLL procedure libc.so. (3258)

> cat $DLC/version
OpenEdge Release 10.2B as of Mon Dec 14 17:00:19 EST 2009
> uname -a
Linux newcastle 2.6.16.13-4-smp #1 SMP Wed May 3 04:53:23 UTC 2006 x86_64 x86_64 x86_64 GNU/Linux

Any idea what I'm missing?

Posted by ChUIMonster on 08-Feb-2011 09:22

As it turns out... /usr/lib64/libc.so is a "ASCII C program text" file on my system.  It looks like a script and refers to /lib64/libc.so.6 as the probable /libc.so.

Plugging that in fixes the problem.

Posted by gus on 08-Feb-2011 13:19

Hmmmm.

I guess I did not test my example program in enough environments.

Isn't the field of data processing exciting and rewarding?

Posted by jankeir on 19-Mar-2012 08:08

Do you also know how to do this on AIX? We've got a shell script right now that (by determining the parent pid of the os-command started command) but that's not very fast.

An API call would be faster, but there's no libc.so in /lib, only libc.a. (AIX 6.1)

Posted by egarcia on 19-Mar-2012 10:56

Hello,

Yes, this can also be done on AIX.

The reference to libc.a is different it has to include shr.o. So the path can be "/usr/lib/libc.a(shr.o)" or "libc.a(shr.o)".

The file shr.o is a module that is included in libc.a (archive format).

     procedure getpid external '/usr/lib/libc.a(shr.o)'cdecl.

     define return parameter pid as long no-undo.
     end.

     def var p as int no-undo.

     run getpid (output p).

     message p.


I hope this helps.

Posted by jankeir on 20-Mar-2012 04:17

Thanks for your reply. Sadly I get the following errors when executing this:

Could not open Dynamic Library: libc.a(shr.o) (8013)

DLL Error : Could not load module /usr/lib/libc.a(shr.o). (8014)

Could not load DLL procedure libc.a(shr.o). (3258)

Posted by jankeir on 20-Mar-2012 04:20

Aha, found it, I need shr_64.o. Thank you very much indeed!

This thread is closed