如何通过在Windows平台上运行的COBOL代码获取进程ID或父进程ID?
答案 0 :(得分: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进行简单的CALL。
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
答案 1 :(得分:0)
我正在回答GNU Cobol,以前的OpenCOBOL。
有一个CALL“C $ GETPID”返回整数值END-CALL
作为库存库的一部分。基本上它调用getpid()或_getpid()
如果您没有链接到标准C库,但可以访问Kernel32.dll,则WinAPI具有GetCurrentProcessId()