1752307 Members
5267 Online
108786 Solutions
New Discussion

PID of a process

 
SOLVED
Go to solution
J15
Frequent Visitor

PID of a process

How do I get the PID of a particular process using lib$getjpi using HP C ?

I'm able to get it for the current process but not for any other.

 

Thanks

6 REPLIES 6
Hoff
Honored Contributor

Re: PID of a process

Guess: You need GROUP or WORLD privilege to poke around with information from other processes on the OpenVMS system.

 

Common related design errors: using process names to identify a target process is not a reliable means of differentiating processes; process names are (usually) unique within a UIC group, but are not unique across UIC groups.

 

Otherwise...  Additional details, please?  What process(es)?  Some example source code?  What programming language?  What is the error code returned from the failed call?  (It's also commonplace to include a reference to the OpenVMS version and platform associaed with questions, but this particular run-time library call is a very old call, and the PID stuff is little changed in probably the last twenty years or so.)

J15
Frequent Visitor

Re: PID of a process

Nothing fancy but just trying to understand the library function ...just trying to get the process ID using lib$getjpi which i'm not getting through.

 

Thanks

Brian Reiter
Valued Contributor

Re: PID of a process

Hoff is right, if you run the code from an account with system privlieges it works, if you don't have the privilege (WORLD or SYSPRV I'd guess) then you get a zero for the PID.

cheers

Brian
Steven Schweda
Honored Contributor

Re: PID of a process

 
Hoff
Honored Contributor
Solution

Re: PID of a process

You're not performing a status check on the return.  OpenVMS error conditions will often point you at the specific problem.  The usual return status checls are for specific condition values and then more generally for odd or even values; successful condition returns are odd.

 

You'll really want to grok the return status values here, as well as the condition value structure definition, and you'll want to understand and specify and check the IOSB values where the IOSB argument is available on an OpenVMS system service or other OpenVMS-related call. These and other details are in the Programming Concepts manual.

 

I'd tend to use sys$getjpi and sys$getjpiw system service calls here, given that C supports pointers, and given that these system service calls are also far more flexible than lib$getjpi.  The lib$ analogs of the OpenVMS system service calls are largely tailored for languages that don't support pointers.  Either path does work, of course.

 

To get the PID of the SMHANDLER process, you'll need to have WORLD privilege, unless your process is in the same UIC group, then you'd need GROUP, unless you're in the same UIC, when you can get the PID without privilege.  And process names aren't distinct across UIC groups - each group can have a SMHANDLER process - and thus the process name identifier is group-specific.

 

If you need to find a process with a particular process name system-wide, then you'll want to use a loop through all processes, and then match the process name and the UIC (and potentially other criteria) against your target process.  (Or you can use the sys$process_scan call with either the sys$getjpi or the sys$getjpiw call looping, to narrow selection of processes that will be returned to you based on more specific target criteria.)

 

Here is example wildcard-loop code from the OpenVMS Programming Concepts manual.

 

Is there any particular reason you've chosen to look at the SMHANDER process here, or was that just a handy target for testing?

J15
Frequent Visitor

Re: PID of a process

Thanks All,

 

Hoff, SMHANDLER was chosen for no particular reason.... just a handy stuff.