Call function in another executables address space

Linux specific questions.
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Call function in another executables address space

Postby wolfman775 » Jul 08, 2011 16:02

Is this possible, can it be done in freebasic, how could I go about doing it?
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: Call function in another executables address space

Postby D.J.Peters » Jul 08, 2011 16:16

wolfman775 wrote:Is this possible, can it be done in freebasic, how could I go about doing it?
Why not ?
if your executable exports something you can use DyLib in same way as it would be a dynamic lib with exported things.

http://www.freebasic.net/wiki/wikka.php ... gDylibload
http://www.freebasic.net/wiki/wikka.php ... ylibsymbol

Joshy
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Postby wolfman775 » Jul 08, 2011 16:31

I tried loading the executable like any other lib with DyLibLoad but it just returns 0, and calling the function causes a segfault :(

Edit:
Realy what I would like is to have a dynamic library in its own adress space, so that multiple executables can communicate through it (At the moment if the both load the same library it is copied into that programs adress space meaning that if one program sets a shared variable in the lib through a function the other executable cannot read that value)
Landeel
Posts: 734
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Postby Landeel » Jul 08, 2011 19:33

Well, it's not a trivial task...

Each executable will have the dynamic library in a separate space.

I can think of 2 possible workarounds:

1) You can get the executables to comunicate with each other using temporary files

2) You can make the first executable run the second one using "open pipe"

As FreeBasic only support unidirectional pipes, you may need to combine the two techniques.

In both cases, variables won't be magically shared between them, you will have to write code for that.
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Postby wolfman775 » Jul 08, 2011 19:44

This is going to take a lot of thinking, because neither of those methods are flexible enough, mostly because I am going to have multiple executables communicating bi-directionally and I am already using the pipe method for something else (Getting a window handle so I can use XReparentWindow) I might just need to implement it using some network protocol the same way XLib does...

Even worse, I will have to do that in multiple threads and I am trying to avoid that because my program is complex enough as it is. If only this could be a lot easier...

I could have a bunch of files (one per app) that contain info that is to be exchanged, and when an app is started then it will be given a file to use and then I could have a list of these files somewhere (An array?), then when an app exits, it must manually delete that file and remove it from the list so it doesn't waste processor time, and even then I am trying to avoid temporary files, so sockets it is...

/Rant

Hopefully someone finds this rant useful.
Landeel
Posts: 734
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Postby Landeel » Jul 08, 2011 21:12

Ouch, that's complex. I think you will have to go with networking then.

In the past I remember reading about a library for DarkBASIC (Windows only), that would share a memory space between 2 applications.

I have never seen such a thing in FreeBASIC, or in Linux.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Jul 08, 2011 23:18

Might give you another possibility: http://www.cyberciti.biz/tips/what-is-d ... usage.html
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Postby sir_mud » Jul 08, 2011 23:58

Try zeroMQ, this is one of the things it was designed for. Header for freebasic available here http://code.google.com/p/freebasic-head ... zmq/zmq.bi

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 4 guests