- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Can i dynamically load a library half way thro...
Operating System - HP-UX
1753521
Members
4798
Online
108795
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2010 09:11 PM
тАО02-23-2010 09:11 PM
Hi stalwarts,
There is this process(lets say A) which keeps running on a system for weeks together, when a transaction is made through the process, I want to check memory leaks and stuff.
For this purpose I made a library which contains wrappers for memory allocations etc (lets call it lib.so ).Currently I am able to get my results when i use LD_PRELOAD=./lib.so and dynamically load it just before the execution of the process( A ).
Now I require to load this library somewhere in between the run of the process (A).
example:
T=0 process A starts
T=10 I want to load my library lib.so
T=20 I want to unload my library.
T = 100000000 process still running
Between times T=10 and T=20 I want my libraby to be accessed and not the original libc.so .
So between T=10 and T=20 my wrappers which i have written for malloc, calloc, realloc and free will be called and not the original frees and mallocs.
before T=10 and afteer T=20 the original mallocs , frees etc would be working.
Is this situation possible?
Can anyone give me pointers how to proceed with this requirement of mine?
Thanks a bunch
Regards,
There is this process(lets say A) which keeps running on a system for weeks together, when a transaction is made through the process, I want to check memory leaks and stuff.
For this purpose I made a library which contains wrappers for memory allocations etc (lets call it lib.so ).Currently I am able to get my results when i use LD_PRELOAD=./lib.so and dynamically load it just before the execution of the process( A ).
Now I require to load this library somewhere in between the run of the process (A).
example:
T=0 process A starts
T=10 I want to load my library lib.so
T=20 I want to unload my library.
T = 100000000 process still running
Between times T=10 and T=20 I want my libraby to be accessed and not the original libc.so .
So between T=10 and T=20 my wrappers which i have written for malloc, calloc, realloc and free will be called and not the original frees and mallocs.
before T=10 and afteer T=20 the original mallocs , frees etc would be working.
Is this situation possible?
Can anyone give me pointers how to proceed with this requirement of mine?
Thanks a bunch
Regards,
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 12:22 AM
тАО02-24-2010 12:22 AM
Re: Can i dynamically load a library half way through a running process?
>Between times T=10 and T=20 I want my library to be accessed and not the original libc.so.
You can't do this. Once a function is called, from a load module, it will continue to call what it found the first time.
Otherwise you will have to use LD_PRELOAD=./lib.so and have it call the libc functions. Then upon loading a shlib, you could have lib.so change what it does.
Note: If you have allocated something with libc then change to deallocate it with your lib.so, you may have problems. Or you may have accounting errors. I.e. a free without it being in your table. Or a malloc assumed without a free.
You can't do this. Once a function is called, from a load module, it will continue to call what it found the first time.
Otherwise you will have to use LD_PRELOAD=./lib.so and have it call the libc functions. Then upon loading a shlib, you could have lib.so change what it does.
Note: If you have allocated something with libc then change to deallocate it with your lib.so, you may have problems. Or you may have accounting errors. I.e. a free without it being in your table. Or a malloc assumed without a free.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 02:27 AM
тАО02-24-2010 02:27 AM
Re: Can i dynamically load a library half way through a running process?
Hi Dennis,
Thanks for replying :)
The lib.so which I have made actually contains the wrappers for libc.so calls.
So when I do LD_PRELOAD=./lib.so to record all the data within these wrappers, I have to use LD_PRELOAD just before i run the exe for the process :(.
From what I could get from your post, I think i am doing the same thing (ie: using LD_PRELOAD and loading lib.so before the start of the process)
I have two doubts.
1) Is there any way i could do LD_PRELOAD while the process is running.
So that the moment i do LD_PRELOAD=./lib.so , the process starts picking up the wrappers for malloc, realloc, calloc and free from lib.so the moment I do LD_PRELOAD. and vice versa for unset LD_PRELOAD.
2)When I open a shell and set LD_PRELOAD, is there any way for me to open one more shell so that both these shells are connected and behave the same way with respect to enviornment variabls and shlibs etc.
example:
lets say I opened shell1 and in this i set LD_PRELOAD=./lib.so
when i open shell2 , is there any way so that i can get to see echo $LD_PRELOAD give the output ./lib.so without havign to set this in shell2?
Why i want to do this is so that on shell1 i shall run the process and on shell two i will dynamically load lib.so when the process is already up. So that the process on shell1 picks up this lib.so on shell2.
Is there any way to get such a kind of situation.
Thanks a million.
Regards
Thanks for replying :)
The lib.so which I have made actually contains the wrappers for libc.so calls.
So when I do LD_PRELOAD=./lib.so to record all the data within these wrappers, I have to use LD_PRELOAD just before i run the exe for the process :(.
From what I could get from your post, I think i am doing the same thing (ie: using LD_PRELOAD and loading lib.so before the start of the process)
I have two doubts.
1) Is there any way i could do LD_PRELOAD while the process is running.
So that the moment i do LD_PRELOAD=./lib.so , the process starts picking up the wrappers for malloc, realloc, calloc and free from lib.so the moment I do LD_PRELOAD. and vice versa for unset LD_PRELOAD.
2)When I open a shell and set LD_PRELOAD, is there any way for me to open one more shell so that both these shells are connected and behave the same way with respect to enviornment variabls and shlibs etc.
example:
lets say I opened shell1 and in this i set LD_PRELOAD=./lib.so
when i open shell2 , is there any way so that i can get to see echo $LD_PRELOAD give the output ./lib.so without havign to set this in shell2?
Why i want to do this is so that on shell1 i shall run the process and on shell two i will dynamically load lib.so when the process is already up. So that the process on shell1 picks up this lib.so on shell2.
Is there any way to get such a kind of situation.
Thanks a million.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 08:35 PM
тАО02-24-2010 08:35 PM
Solution
>1) Is there any way I could do LD_PRELOAD while the process is running.
No. As I said: Once a function is called, from a load module, it will continue to call what it found the first time.
>the process starts picking up the wrappers for malloc, realloc, calloc and free from lib.so the moment I do LD_PRELOAD
You need to always do LD_PRELOAD and dynamically sense whether your wrappers do their normal work or just bypass to libc.
>2) When I open a shell and set LD_PRELOAD, is there any way for me to open one more shell so that both these shells are connected
Not that I know. But a shell isn't important, only your process is.
You should never export LD_PRELOAD. You must set it just for one command:
LD_PRELOAD=./lib.so command ...
>is there any way so that I can get to see echo $LD_PRELOAD give the output ./lib.so without having to set this in shell2?
I'm not sure how good this will do:
$ (LD_PRELOAD=xx; echo $LD_PRELOAD)
>So that the process on shell1 picks up this lib.so on shell2.
No, you can't do that.
As I mentioned above, always use lib.so. And have the wrappers there dynamically sense what you want to do. Possibly looking at shared memory, or a user signal.
No. As I said: Once a function is called, from a load module, it will continue to call what it found the first time.
>the process starts picking up the wrappers for malloc, realloc, calloc and free from lib.so the moment I do LD_PRELOAD
You need to always do LD_PRELOAD and dynamically sense whether your wrappers do their normal work or just bypass to libc.
>2) When I open a shell and set LD_PRELOAD, is there any way for me to open one more shell so that both these shells are connected
Not that I know. But a shell isn't important, only your process is.
You should never export LD_PRELOAD. You must set it just for one command:
LD_PRELOAD=./lib.so command ...
>is there any way so that I can get to see echo $LD_PRELOAD give the output ./lib.so without having to set this in shell2?
I'm not sure how good this will do:
$ (LD_PRELOAD=xx; echo $LD_PRELOAD)
>So that the process on shell1 picks up this lib.so on shell2.
No, you can't do that.
As I mentioned above, always use lib.so. And have the wrappers there dynamically sense what you want to do. Possibly looking at shared memory, or a user signal.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP