Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Process ID from Cobol

Status
Not open for further replies.

ttmac

Technical User
Aug 16, 2002
105
IE
Is it possible, using Microfocus Cobol on a unix platform to query the system for the Process ID/Thread ID of the executing program?

Tom
 
Hi Tom,

You can use the COBOL pointer feature to access system areas in an IBM mainframe environment. You also may be able to do that in other environments.

Your best bet is to find a UNIX forum and ask how to chain through the UNIX system data, then determine how to do that in COBOL using pointers. At that point you might be able to get some help here.

If you're lucky there may be somebody here that has done something similar and can help.

Regards, Jack.
 
ttmac,

I don't know about MF Cobol, but RM/Cobol on Unix provides for executing a system command via a CALL "SYSTEM" USING CMD-STRING feature. You can then execute an arbitrary command by building it the CMD-STRING.

If you have a similar feature available, you should be able to run something like:

ps -u $(LOGNAME) > my-processes.txt

You will then be able to turn around and read "my-processes.txt" as a simple sequential text file and search for the process you are looking for. If you put the above command string in a uniquely named script, you should be able to find that script name in the command text portion of the ps output, and use the corresponding parent process id (PPID) to identify your process id.

I've not actually done this. Fortunately, RM/Cobol also provides a callable routine "C$GetSysInfo" that returns, among other things, the specific process id. But I am sure that you should be able to get something like this to work.

"Code what you mean,
and mean what you code!
But by all means post your code!"

Razalas
 
Slade, Razalas,

Thanks for the quick response and the assistance.

I will post again to let you know how I get on.

Cheers,

Tom.
 
When your running program does a 'Call "SYSTEM"' it will give birth the a child process with it's own PID.(easy right? Why do women make such a fuzz about that).
As long as you realize that and go and look for the PID of the parent istead of it's own PID then it will be OK.

If your program is executed by a script it is more easy to "SET" an environment variable with the value of the PID. This can be retrieved using DISPLAY/ACCEPT UPON/FROM ENVIRONMENT NAME/VALUE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top