Am 2010-04-10 15:17, schrieb MK:
Chris Vine wrote:
This won't work.  X won't allow two processes to share the same
resources.
If you are fork()ing to exec() another program, then you will need to
start a new thread and fork() from that
You don't have to thread it.  I presume the purpose has nothing to do
with gtk.  So you might as well quit() gtk immediately in the fork.
After that you can do whatever you want.

#include<gtkmm.h>
#include<iostream>

using namespace std;

vector<pid_t>  Pids;

void buttonpress() {
        static int i = 0;
        i++;
        pid_t pid = fork();
        cerr<<  i<<  ": "<<  pid<<endl;
        if (!pid) {
                Gtk::Main::quit();
                while (1) {
                        sleep(1);
                        cerr<<  i<<  " hello world"<<  endl;
                }
        } else Pids.push_back(pid);
}

int main(int argc, char *argv[]) {
        Gtk::Main kit(argc, argv);
        Gtk::Window win;
        Gtk::VBox box;
        Gtk::Button but("click me");

        win.set_title("gtkmm test");
        win.set_size_request(400,200);
        win.add(box);

        box.pack_start(but);
        but.signal_clicked().connect(
                sigc::ptr_fun(buttonpress),false);

        win.show_all();
        kit.run(win);

        vector<pid_t>::iterator it = Pids.begin(),
                end =  Pids.end();
        while(it != end) kill(*(it++),9);

        return 0;
}

That's not really beautiful...
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to