Solved

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

Posted on 2004-04-05
12
896 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
0
Comment
Question by:rxue_expertexchange
  • 6
  • 4
  • 2
12 Comments
 
LVL 14

Expert Comment

by:daveslater
ID: 10758335
0
 
LVL 14

Expert Comment

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

Dave
0
 

Author Comment

by:rxue_expertexchange
ID: 10758790
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?
0
 
LVL 14

Expert Comment

by:daveslater
ID: 10758922
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
http://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
0
 

Author Comment

by:rxue_expertexchange
ID: 10760214
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.

0
 
LVL 14

Expert Comment

by:daveslater
ID: 10760445
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
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:rxue_expertexchange
ID: 10760898
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.
0
 
LVL 27

Assisted Solution

by:tliotta
tliotta earned 70 total points
ID: 10761618
You can use the following:

  #include <sys/types.h>
  #include <unistd.h>

  pid_t getpid(void);

This and related APIs are documented under the UNIX-type APIs for OS/400.

0
 

Author Comment

by:rxue_expertexchange
ID: 10768291
But you can only get the process ID from the getpid(), how can I get the process name attached with the process ID?
0
 
LVL 27

Accepted Solution

by:
tliotta earned 70 total points
ID: 10769377
Process name isn't exactly meaningful under OS/400. I'd first guess what you want is job name instead. Alternatively, perhaps you want to retrieve the name of the program that calls getpid()?

Example place to start for job name might be Qp0wGetJobID()--Get Qualified Job Name and ID for Process ID. Get the pid with getpid() and send it to Qp0wGetJobID().

Now, getting the "name" of a program needs a bit of clarification. An object name has essentially three parts: library, name and type. The fully-qualified name of a program can change while the program is running. The type will always be *PGM, but the library qualifier can change for a number of reasons, e.g., a program moving into QRPLOBJ because it was changed while active. Likewise, the unqualified name can change simply by a rename operation.

Those may be unlikely, but they might need to be accounted for depending on exactly why you need them within the program while it runs.

Commonly, you'd create a function that starts by sending a message to the caller. The function then immediately receives that message from the caller's queue and extracts the name attribute from the message and returns that back to the caller. That will generally give you the unqualified name of the program object. You might name this function GetModuleName(). You can create this as a CL procedure using basic CL commands or create it in C if you wish using message handling APIs. Unless it's going to be called a lot, it probably doesn't matter. In either case, I'd create it as a procedure rather than a program. But I also see above that you really want a function -- returning a function value. Since CL procedures cannot return function values, you'll want to use C rather than CL.

A fundamental flaw with this is that the library portion of the fully-qualified object name isn't available.

There are "better" ways of finding the program object's name, but the available techniques change with different releases of OS/400. Since you seem to be distributing to multiple, possibly unknown releases, and since you probably don't want to be getting too deep into MI programming quite yet, sending/receiving a message is probably best. A CL procedure is easy for this. To get fully-qualified name without resorting to MI gets ugly, and I think Dave has already alluded to that.

Unfortunately, I don't have a C example. But if you're clear on what you want and the examples Dave has referenced seem to describe the info you need, we can supply the APIs you'll want to use.

Tom
0
 

Author Comment

by:rxue_expertexchange
ID: 10806348
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.
0
 

Author Comment

by:rxue_expertexchange
ID: 11172230
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now