Consultor Eletrônico



Kbase P111035: 4GL: How to get a progress procedure's name from its UNIX process id using 4GL?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   18/11/2005
Status: Unverified

GOAL:

How to get a running progress procedure's name from its UNIX process id using 4GL?

FIX:

The following sample code uses the UNIX 'ps' command to extract the name of a running progress '.p' procedure given its UNIX process id:
DEFINE VARIABLE iProcess AS INTEGER NO-UNDO.
DEFINE VARIABLE cProgram AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTempDataFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCommand AS CHARACTER NO-UNDO.
ASSIGN
iProcess = 3967
cTempDataFile = "TempData.out"
cCommand = "ps" + CHR(32) +
"-ef" + CHR(32) +
"|" + CHR(32) +
"grep" + CHR(32) +
STRING(iProcess) + chr(32) +
">" + chr(32) +
cTempDataFile.
/* Execute the command and send its output to "TempData.out" */
OS-COMMAND SILENT VALUE(cCommand).

RUN ParseTempDataFile.
/* Extrace the name of the .p procedure from the output file */
PROCEDURE ParseTempDataFile.
DEFINE VARIABLE cProProcExt AS CHARACTER NO-UNDO.
DEFINE VARIABLE cLine AS CHARACTER NO-UNDO.
DEFINE VARIABLE iRIndex AS INTEGER NO-UNDO.
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
DEFINE VARIABLE iStartPosition AS INTEGER NO-UNDO.
DEFINE VARIABLE iEndingPosition AS INTEGER NO-UNDO.
ASSIGN
cProProcExt = ".p".

INPUT FROM VALUE(cTempDataFile).
REPEAT:
IMPORT UNFORMATTED cLine.
iRIndex = R-INDEX(cLine, " -p ").
IF iRIndex = 0 THEN NEXT.

ASSIGN
iStartPosition = iRIndex + 4
iEndingPosition = R-INDEX(cLine, cProProcExt) + 2
iLength = iEndingPosition - iStartPosition
cProgram = SUBSTRING(cLine, iStartPosition, iLength).
MESSAGE cProgram
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
INPUT CLOSE.
OUTPUT CLOSE.
END PROCEDURE.