如何通过在 windows 平台上运行的 COBOL 代码获取进程 ID 或父进程 ID?
问问题
711 次
2 回答
1
假设 Micro Focus COBOL,谷歌会得到你http://community.microfocus.com/microfocus/cobol/net_express__server_express/w/knowledge_base/6539.obtaining-the-process-id-for-cobol-application.aspx
作为 Micro Focus COBOL 的用户,您可以获得支持登录并联系他们/他们的社区。
该链接建议对标准 C 函数 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
于 2013-09-30T14:40:31.133 回答
0
我正在回答 GNU Cobol,即以前的 OpenCOBOL。
有一个 CALL "C$GETPID" RETURNING integer-value END-CALL
作为股票库的一部分。基本上它调用 getpid() 或 _getpid()
如果您没有链接到标准 C 库,但可以访问 Kernel32.dll,则 WinAPI 具有 GetCurrentProcessId()
于 2013-09-30T18:17:45.843 回答