Getting the Process ID -
Posted in 1995
We had synchronicity at the shop, and had to extract the PID from the
system for a report...Saw the posting the other day, and here's a shar
of a solution using the real UNIX function instead of fgl_getenv("PID")
which did not work. ( No surprise to me :-) )
By the way Joe Lumbley, if INFORMIX will pull their heads out, I will
supply the wet wipes...The docs on using C functions are split up making
it almost "unsolvable" to use C functions, but fortunately I've had enough
"hack-time" with the product. It's really amazing how much trouble the
boys at INFORMIX went through to make in-line C-code an impossibility. And
INFORMIX don't tell me in-line C-code is a hard thing to do...I already
knew that! You've got in-line SQL in ESQLC but I guess you can't have it
both ways... :-)
Anyway, here's the solution for a DG/UX box:
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by tschaefe on Tue Jan 31 11:17:25 EST 1995
# Contents: getpid.4gl fgiusr.c get_pid.c gpid.c makegpid
echo x - getpid.4gl
sed 's/^@//' > "getpid.4gl" <<'@//E*O*F getpid.4gl//'
MAIN
DEFINE pid INTEGER
DEFINE nargs INTEGER
LET nargs = 0
LET pid = 0
CALL get_pid(nargs) RETURNING pid
DISPLAY "PID[",pid,"]"
END MAIN
@//E*O*F getpid.4gl//
chmod u=rw,g=rw,o=r getpid.4gl
echo x - fgiusr.c
sed 's/^@//' > "fgiusr.c" <<'@//E*O*F fgiusr.c//'
#include "fgicfunc.h"
int get_pid();
cfunc_t usrcfuncs[] = { "get_pid",get_pid,1, 0, 0, 0 };
@//E*O*F fgiusr.c//
chmod u=rw,g=rw,o=r fgiusr.c
echo x - get_pid.c
sed 's/^@//' > "get_pid.c" <<'@//E*O*F get_pid.c//'
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
get_pid( nargs )
int nargs;
{
int pid = 0;
popint( &nargs );
pid = getpid();
retint( pid );
return(1) ;
}
@//E*O*F get_pid.c//
chmod u=rw,g=rw,o=r get_pid.c
echo x - gpid.c
sed 's/^@//' > "gpid.c" <<'@//E*O*F gpid.c//'
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main()
{
int pid = 0;
int ppid = 0;
pid = getpid();
ppid = getppid();
printf("PID:[%d]PPID[%d]\\n", pid, ppid );
}
@//E*O*F gpid.c//
chmod u=rw,g=rw,o=r gpid.c
echo x - makegpid
sed 's/^@//' > "makegpid" <<'@//E*O*F makegpid//'
fglpc getpid.4gl
cfglgo fgiusr.c get_pid.c -o rgetpid
@//E*O*F makegpid//
chmod u=rwx,g=rwx,o=rx makegpid
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\\!!!
13 23 163 getpid.4gl
3 13 93 fgiusr.c
12 28 169 get_pid.c
11 27 177 gpid.c
2 7 54 makegpid
41 98 656 total
!!!
wc getpid.4gl fgiusr.c get_pid.c gpid.c makegpid | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0
#------ cut here
What you get:
getpid.4gl - demo program to illustrate getting the PID
fgiusr.c - voodoo magic linkage to r4gl
get_pid.c - c function to get the PID
gpid.c - the c program
makegpid - script to make a r4gl runner -- see the 4GL Ref Manual
for more info.
To run the 4go:
$ rgetpid getpid
Enjoy!
\\\\|//
(o o)
==============================---o00--(_)--00o---============================
Tim Schaefer tschaefe@gate.net
The Computer Business Company, Inc. http://www.gate.net/~tschaefe
Coconut Creek, FL, USA DILLYGAF!
No animals used in the making of this message were harmed in any way!
=============================================================================