2013-09-30 74 views
0

如何通過在Windows平臺上運行的COBOL代碼獲取進程ID或父進程ID?getpid在Windows平臺上的COBOL

+0

http://msdn.microsoft.com /en-us/library/windows/desktop/ms683215(v=vs.85).aspx和父進程ID,通常最好將其作爲參數傳遞,或者你必須枚舉進程,找到你的PID,檢查父PID ,並希望父進程尚未關閉,並重新使用其PID。 –

回答

0

我回答的是以前的OpenCOBOL的GNU Cobol。

有一個叫 「C $ GETPID」 回整數值END-CALL

的股票庫的一部分。基本上,它調用GETPID()或_getpid()

如果沒有鏈接到標準C庫,但有機會獲得的Kernel32.dll,在WinAPI的具有GetCurrentProcessId()

+0

謝謝,我已將kerner32.dll包含在我的項目(visual cobol-visual studio)中,然後下面的命令將我的進程ID提取給我 - 調用「GetCurrentProcessId」給出ProcessId,01 ProcessId pic s9(9)comp-5。 – user1085296

1

假設微焦點COBOL,谷歌將讓你http://community.microfocus.com/microfocus/cobol/net_express__server_express/w/knowledge_base/6539.obtaining-the-process-id-for-cobol-application.aspx

微焦點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 
+0

感謝您的回覆......只有一個疑問,如果我在Windows平臺下運行此COBOL prog,這項工作是否會奏效? – user1085296

+0

該鏈接表示Net Express/Server Express。如果您有更具體的Windows環境,我的答案是想讓您註冊Micro Focus並根據您的具體情況爲他們提供準確快速的支持。你標記了MicroFocus,所以我假設你有它。從COBOL接口到C非常簡單,大多數情況下它將按照Micro Focus示例中的說明工作。 –