Winapi windows平台上COBOL中的getpid

Winapi windows平台上COBOL中的getpid,winapi,cobol,microfocus,Winapi,Cobol,Microfocus,如何通过运行在windows平台上的COBOL代码获取进程id或父进程id?假设Micro Focus COBOL,google将为您提供 作为Micro Focus COBOL的用户,您可以获得支持日志并与他们/他们的社区联系 该链接建议对标准C函数getpid进行简单调用 Obtaining the process ID for COBOL application This article explains how to capture the process ID for the cur

如何通过运行在windows平台上的COBOL代码获取进程id或父进程id?

假设Micro Focus COBOL,google将为您提供

作为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

我是GNUCobol的负责人,以前叫OpenCOBOL

有一个调用“C$GETPID”返回整数值结束调用

作为股票库的一部分。基本上它调用getpid()或_getpid()


如果您没有链接到标准C库,但可以访问Kernel32.dll,则WinAPI具有GetCurrentProcessId()

,对于父进程ID,通常最好将其作为参数传递,或者您必须枚举进程,找到PID,检查父进程PID,希望父进程没有关闭并重新使用其PID。感谢您的回复…只有一个疑问,如果我在windows平台下运行此COBOL程序,这会起作用吗?链接上显示Net Express/Server Express。如果您有一个更具体的Windows环境,我的答案是让您向Micro Focus注册,并从他们那里获得准确、快速的支持。你标记了微焦点,所以我假设你有。从COBOL到C的接口非常简单,大多数情况下它都会像Micro Focus示例中所示那样工作。谢谢,我已经在我的项目(visual COBOL-visual studio)中包含了kerner32.dll,然后下面的命令获取了进程ID-调用“GetCurrentProcessId”,给出了进程ID,01 ProcessId pic s9(9)comp-5。