dlopen from a child process to access parent process functions

Andrew Haley aph@redhat.com
Sun Jun 22 11:39:00 GMT 2008


Ravindra Jejurikar wrote:
> Hello,
>     I would like a child process to have access to the parent process's functions using dlopen(). Is this possible?

Certainly, but you can't do it with system().

system() combines two calls, fork(), and execv().  execv() completely
replaces the child's copy of the parent process image, so after
excecv() it's no longer possible to call functions in that image from
the child.

> Reason to have two binaries: Eventually, I want to call some perl
> code from the C code and the perl code should be able to access some
> C functions. So I am trying with two different C binaries to start
> with.

> Is there an easier way to do what I am trying. I cannot have my perl
> code as the master with the C code as a .so (complex legacy C code -
> in short)

That's what you are going to have to do.  Either that or connect the
two processes with pipes.

Andrew.



More information about the Gcc-help mailing list