سؤال

I have a shared library with 2 methods (among others of course) that i want to port to linux:

GetProcessName() - Should get the executable name or path (either would do)
GetModuleName() - Should return the name of the module that's running the code (either dll or exe).

In a windows environment I use GetModuleFileName with a different variation for both methods.

I've seen plenty of solutions for getting the process name, but most of them seem kinda Hacky.
And I haven't found a solution for getting the module name.

Is there a similar function in linux ?
How can I implement them ?

هل كانت مفيدة؟

المحلول

Since there's some confusion, here are the two steps to get the "module" data for the current function.

  1. Get the current function, either by the IP register or by calling a small function that just returns __builtin_return_address(0). Yet another method is to just take &foo inside foo().
  2. Call dladdr, passing the address of the current function.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top