Q:

How to determine if a so file has been loaded or not?

I have two shared libraries: a.so and b.so.
a.so must have be loaded before b.so is loaded. And, a.so might be loaded by other modules, not by me.
So, I want to determine if a.so has been loaded before I call dlopen("b.so", ...).
Under Windows, I can use GetModuleHandle("a.dll") to determine that by examining the return value. That is, a.dll has been loaded if the return value is not null; otherwise it is not loaded yet.
Is there a GetModuleHandle-like function under Linux?

A:

You can actually use dlopen to check this, with the RTLD_NOLOAD flag:

Don't load the library.  This can be used to test if the library is already resident (dlopen() returns NULL if it is not, or the library's handle if it is resident).

A:

determine if a.so has been loaded before I call dlopen

That is almost certainly the wrong thing to do (i.e. you are asking the wrong question).
Consider a multithreaded program, where you ask above question (and receive positive answer) in thread 1, just as thread 2 calls dlclose(a_so_handle)s and unloads a.so.
Conversely, you may get a negative answer in thread 1, just as thread 2 finishes dlopen("a.so", ...), and loads it.
The right thing to do is simply do dlopen("a.so", ...); dlopen("b.so", ...);.
If a.so has already been loaded, the first dlopen will simply increment its reference count. If it has not yet been loaded, it will be.

But I still want to know a so's loading state at runtime.

You can't know that state reliably. The answer you are getting is: a.so may or may not be currently loaded.

