On 17 Mar 2012, at 18:55, vectrum wrote:
> 
> I want to display output of a simple fork call, how fltk manages it?

What are you hoping to achieve here?

It's unlikely that both sides of the fork() call can access the fltk context: 
fork() maps a new process which, whilst it inherits some things from the parent 
process, is nonetheless unique.

In that case, it is not likely that the child process can access the fltk 
context directly (or at least, not safely), so you would need to use some form 
of IPC to allow the child to write back to the GUI that exists in the parent 
process. The fork will share descriptors between the parent and the child 
(well, the child gets a copy of the parents...) so you can use that to set up a 
pipe between the two processes to send messages back and forth.
Though for myself, I might go for a named pipe, or even a network socket (since 
the socket based IPC would then be network transparent so easy to move to 
another host or whatever if needed.)

An alternate might be to have the child process exec() an new state and start 
its own fltk GUI...


Is fork() even the thing you want to do? Creating another thread in the parent 
process is much simpler and both threads would have ready access to the GUI 
then (since they map into the same process space.)

Threads are probably easier and simpler than having distinct precesses for a 
huge range of tasks these days.

Can you describe what you are hoping to do - maybe then someone can describe 
ways to get there...



> 
> #include <unistd.h>
> int main()
> {
> pid_t pid;
> const char *name;
> pid = fork();
> if (pid == 0)
> {
> name = "I am the child";
> write(1, name, 15);
> write(1, "\n", 2);


Um, why not just use printf() / fprintf() for the text output here?

> }
> else
> {
> name = "I am the parent";
> write(1, name, 16);
> write(1, "\n", 2);
> }
> return 0;
> }
> 
> I want to display the output of this code on a fltk based label or
> text box. Is it possible?

Yes, but which way to do it will depend on what result you are really trying to 
get, so maybe if you can describe what you are doing in more detail, that will 
help identify how best you might proceed...



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to