Re: Gtkmm and fork()



I have been trying MKs code, but it isn't working.

#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();
int i = 6;
               while (i) {
                       sleep(1);
                       cerr << i << " hello world" << endl; i--;
               }
       } 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;
}


Output:
adam Adam:~/Pulpit$ ./a.out 
1: 5874
1: 0
6 hello world
5 hello world
4 hello world
3 hello world
2 hello world
1 hello world
a.out: Fatal IO error 11 (Resource temporarily unavailable) on X server
:0.0.
a.out: ../../src/xcb_io.c:249: process_responses: Assertion `(((long)
(dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
Aborted (core dumped)




Adam Chyla [PL] wrote:
> 
> Hi. 
> I have that code:
> 
> void MainWindow::on_ok_clicked()
> {
>    pid_t pid = fork(); // There is an error
>    switch (pid)
>    {
> //...
>    }
> }
> 
> When I compiled program the gtkmm returns:
> Mer: ../../src/xcb_io.c:249: process_responses: Assertion `(((long)
> (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
> Mer: ../../src/xcb_io.c:249: process_responses: Assertion `(((long)
> (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
> Aborted (core dumped)
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Gtkmm-and-fork%28%29-tp28197014p28209445.html
Sent from the Gtkmm mailing list archive at Nabble.com.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]