Skip to main content

Obtaining the process ID for COBOL application

  • February 15, 2013
  • 0 replies
  • 1 view

This article explains how to capture the process ID for the currently running COBOL application.

Problem:

How can the process ID (PID) within a running COBOL program be captured?

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.


  1. Sample COBOL code fragments
  2. Sample program fragment
  3. 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

  4. Define the data item where the process id should be returned

    01 current-pid long

    PROCEDURE DIVISION

  5. Call 'getpid' returning current-pid

The returned integer can be used as a part of temporary filenames, or to identify log file entries etc.

Old KB# 14408