Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C, is it possible to integrate new code in a running process by recompiling a dynamic library?

Tags:

python

c

I am picking up C in order to speed up some bits of a large python project. In order to add new functions to a continuously running python script, I have it occasionally check a .py file and integrate it's contents. I was wondering if there was a way of doing the equivalent in C. Is there a way to have it pick up the contents of a dynamic library on the fly?

like image 615
John Gann Avatar asked Oct 29 '13 13:10

John Gann


1 Answers

Yes, you need to use dlopen to access the library rather than linking at compile time, then dlsym to access functions within it. To switch to a new library you'll need to dlclose the handle and create a new one - wrapping this in a module to handle all of it is not a terribly difficult task.

like image 97
Oliver Matthews Avatar answered Nov 14 '22 21:11

Oliver Matthews