>
> On 17 Mar 2012, at 18:55, vectrum wrote:
> >=20
> > 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...
>
>
>
> >=20
> > #include <unistd.h>
> > int main()
> > {
> > pid_t pid;
> > const char *name;
> > pid =3D fork();
> > if (pid =3D=3D 0)
> > {
> > name =3D "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 =3D "I am the parent";
> > write(1, name, 16);
> > write(1, "\n", 2);
> > }
> > return 0;
> > }
> >=20
> > 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...
>
>
>Thank you. > It's unlikely that both sides of the fork() call can access the > fltk = > context: If I'm not mistaken, this might be the reason why my code gives two different output. In CLI, it prints both write calls (child and parent) but in eclipse, it prints only child call. > What are you hoping to achieve here? Well, as I've said, I try to understand how a gui library handles system call so in order to clarify the matter I used this simple sys call as an example. > ...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. ---(i) > ...so you can use that to set up a pipe between the > two processes to > send = messages back and forth.--(ii) Do I have to use the *nix native IPC call or does fltk has its own IPC function which I can use as a substitute if I want to achieve what you suggested, the two instances(i) and (ii). I've heard that QT has its own signal, slot etc to handle this kind of job. QT also has DBus module by which it interacts with OS but I have no such knowledge to comprehend this, only getting abstruct concept while going the documents available in the web. The main point I try to understand is how a gui library interacts with unix system call and other system tools. If I develop a console (CLI) based program, and later implement the same program in gui then what I need to do. Rewrite it with C++ and fltk or develop a gui (with buttons, labels, text boxes etc) and attach the native c program to it. Bottom Line? :)) Do I need to know C programming in order to learn unix system programming using fltk and C++? Lookin for your further suggestion.. Thanks again... _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

