We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to get the current calling process's name in AS400

rxue_expertexchange
on
Medium Priority
1,037 Views
Last Modified: 2008-02-01
I am trying to move a windows DLL to the AS400 platform. There is a function called GetModuleName() in the current DLL file, what this funcation does is to get the application's name of the current process which is calling the DLL file.  However, I couldn't find a equivalent function in the AS400, I would be very appreciated if anybody could provide a sample code that can do the same thing as the GetModuleName() does. Thanks
Comment
Watch Question

Ps
if you need to get the entire program stack I have a routine - but it has a larger overhead

Dave

Author

Commented:
Thanks, Dave
The DLL is written in C. I am a newbie in AS400, and don't know much about the code you posted. Is there anyway to convert those code to C, or Is there any functions in AS400 like getpid(), getprocessname() I can call?
Hi

one thing first do you want module or program name, if it is actual module (ie from a service program that has multiple modules) the I will need to post a different answer.

I do not know much about C so it will take a 2 step solution.
I hope that you now how to call another program in C passing either 1 or 2 parms

The programs are CL programs that will be in source file QCLSRC

the first call will get your current program id
see accepted answer
https://www.experts-exchange.com/Programming/Programming_Platforms/AS400/Q_20873205.html
Note the line in the accepted answer
DCL        VAR(&PGM) TYPE(*CHAR) LEN(10) VALUE('WCM')  
the value is what you will call the program ie I have compile the CL to program WCM

then use this value to call the CL program above this will then get the program that called your C program


Because I am not that good with C and you are new the the 400 it may take a bit but we will get there :-)

Dave

Author

Commented:
Hi, Dave

Does that mean I have to create the extra CL program, and then call the CL program from the C to get the calling process's name. If so, I get some problems on that:
1) Not quite sure how to get the return value(which is the calling process's name in this case) from CL program in C;
2) When we deploy this solution to other servers, we have to deploy one more extra CL program.

Hi
You can do it with a system API, but this is a bit slower and I will need to dig out the code. The plus side is that it will be a function that can be included like other C functions as a service program.

It will take me a few days as I am a bit busy at work

In anyone else can do it faster please join in.

Dave

Author

Commented:
Hi, Dave

System API might be my prefered way. I don't worry too much about it's slower, since it will be called only once during the initialization. Actually, I just found there is an API called "getpid()" in AS400, but still don't know how to figure out the process name from this API.
Take your time, Dave, I am not urgent on this right now, because I can't test it out untill I get the access to the AS400 in the next week or the week after next. Once I get the access, I will also try your way mentioned above, if it works and there is no better way, I might accept it.
Thanks for your time.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
But you can only get the process ID from the getpid(), how can I get the process name attached with the process ID?
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thank you all for your advices, guys
I am still waiting for the access to the AS400 system and then I can test out your ideas. I will definitely let you know how it is going after I start my testing.

Author

Commented:
After poking around on the AS400 system, finally got some ideas about it and you guys' comments got more meaningful to me, Thanks.
What I really need is the program name, and don't care about the library.
The Qp0wGetJobID() API is good for me and works. So I will accept Tom's comment.
Dave's way could be a good solution, but I am really not familar with CL and don't know how to combine it with my C code seamless, so I haven't try it yet.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.