Domanda

How to get process id or parent process id through a COBOL code running on windows platform?

È stato utile?

Soluzione

I'm answering for GNU Cobol, formerly OpenCOBOL.

There is a CALL "C$GETPID" RETURNING integer-value END-CALL

as part of the stock library. Basically it calls getpid() or _getpid()

If you are not linking to standard C libraries, but have access to Kernel32.dll, the WinAPI has GetCurrentProcessId()

Altri suggerimenti

Assuming Micro Focus COBOL, google will get you http://community.microfocus.com/microfocus/cobol/net_express__server_express/w/knowledge_base/6539.obtaining-the-process-id-for-cobol-application.aspx

As a user of Micro Focus COBOL, you can obtain a support log-on and contact them/their community.

The link suggests a simple CALL to the standard C function getpid.

Obtaining the process ID for COBOL application

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.

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.

Old KB# 14408
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top