Operating System - Linux
1751924 Members
4922 Online
108783 Solutions
New Discussion юеВ

Re: Reading shared libraries using pstat_getprocvm() call

 
sanjay khuntia
Occasional Contributor

Reading shared libraries using pstat_getprocvm() call

Hi All,

I m trying to write a program similar to the ldd command. I have a list of process ids and for each of that process, I need to retrieve the list of libraries loaded for that particular process. Can we use pstat_getprocvm() to get the virtual address space of the process? What is PS_SHARED_LIBRARY in pst_vm_status.pst_flags?

 

 

P.S.This thread has been moved from HP-UX>System Administration to HP-UX > languages- HP Forums Moderator

4 REPLIES 4
Don Morris_1
Honored Contributor

Re: Reading shared libraries using pstat_getprocvm() call

Yes, you can use pstat_getprocvm() to get the virtual objects affiliated with a process... that's rather what it is there for, after all.

I find myself at a bit of a loss as to your other question: "What is PS_SHARED_LIBRARY in pst_vm_status.pst_flags?". It is a flag that means that this virtual object is a Shared Library [at least as far as VM knows]. (My puzzlement stems because this verges on the really obvious, so I'm wondering if I'm missing some deeper nuance to your question). Pulling the curtain back just a little, this gets lit whenever the VM metadata describing the object has a different flag (kernel internal) which signifies the object is a shared library. That flag gets lit by either explicit kernel internal use (exec path internals) or use of MAP_SHLIB via the original mmap().
sanjay khuntia
Occasional Contributor

Re: Reading shared libraries using pstat_getprocvm() call

Firstly I want to get the address space of the process (may be a file) and then I want the offset where the dynamically linked libraries are listed.
Don Morris_1
Honored Contributor

Re: Reading shared libraries using pstat_getprocvm() call

Ok, and that's what pstat_getprocvm() *does*. It walks the virtual objects in the process virtual address space and returns properties for each one. You have to iterate to find the shared libraries -- there may not be any particular offset they start from [MPAS processes], and they will almost certainly be mixed in with other shared objects. Just note the virtual addresses [aka offset within the process virtual address space] as needed when you encounter the shared libraries on the iteration.

And I have no idea what you meant by "the process (may be a file)". Certainly the process may be backed by a binary executable or a shell script file... most are other than kernel daemons [and you can argue they're backed by /stand/vmunix anyway].
Dennis Handly
Acclaimed Contributor

Re: Reading shared libraries using pstat_getprocvm() call

>I'm trying to write a program similar to the ldd command.

You're trying to write a program similar to the difficulty of glance or gdb, not ldd, if you want to look at other processes.

Of course on 11.31, pstack(1) handles this fine.

>then I want the offset where the dynamically linked libraries are listed.

This is not available. Only dld knows where this is. You would have to use dlmodinfo(3C) and ttrace(2).
See your other topics:

http://h30499.www3.hp.com/t5/System-Administration/sl-listing-per-process/m-p/4148219

http://h30499.www3.hp.com/t5/System-Administration/listing-all-sl-files-related-to-a-process/m-p/4148866