How to get process id or parent process id through a COBOL code running on windows platform?
Asked
Active
Viewed 789 times
0
-
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683215(v=vs.85).aspx and for parent process ID, generally best to pass that as argument, or you have to enumerate processes, find your PID, check the parent PID, and hope that the parent process has not closed and had its PID re-used. – David Heffernan Sep 30 '13 at 13:19
2 Answers
1
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

Bill Woodger
- 12,968
- 4
- 38
- 47
-
Thank you for your reply...Just one doubt, will this work if I run this COBOL prog under windows platform? – Aravind Sep 30 '13 at 14:57
-
The link says Net Express/Server Express. If you have a more specific Windows environment, the idea of my answer is for you to register with Micro Focus and get accurate and rapid support from them for your specifics. You tagged MicroFocus, so I'm assuming you have it. Interfacing to C is pretty simple from COBOL, mostly it will work as shown in the Micro Focus example. – Bill Woodger Sep 30 '13 at 15:59
1
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()

Brian Tiffin
- 3,978
- 1
- 24
- 34
-
Thank you, I have included the kerner32.dll in my project(visual cobol- visual studio), then the following command fetched me the process ID - call "GetCurrentProcessId" giving ProcessId, 01 ProcessId pic s9(9) comp-5. – Aravind Dec 11 '13 at 12:08