This article explains how to capture the process ID for the currently running COBOL application.
Resolution:
To capture the process ID for a currently running COBOL application, you can code a COBOL CALL statement to use the system function getpid(). The standard C libraries contain the function getpid(), which can easily be called/used from within a COBOL program.
- Sample COBOL code fragments
- Sample program fragment
-
Include the ctypes copy file from within the COBOL product directory as the first line in the COBOL program.
copy '$COBDIR/demo/c-cobol/ctypes.cpy'
WORKING-STORAGE SECTION
DATA DIVISION
-
Define the data item where the process id should be returned
01 current-pid long
PROCEDURE DIVISION
- Call 'getpid' returning current-pid
The returned integer can be used as a part of temporary filenames, or to identify log file entries etc.



