Re: Gtkmm and fork()
- From: Chris Vine <chris cvine freeserve co uk>
- To: "Adam Chyla [PL]" <adam chyla gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: Gtkmm and fork()
- Date: Sun, 11 Apr 2010 17:42:38 +0100
On Sun, 11 Apr 2010 08:23:56 -0700 (PDT)
"Adam Chyla [PL]" <adam chyla gmail com> wrote:
> 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)
You should call _exit() (and incidentally NOT exit()) at the end of the
child process. (That is at the end of the if block representing the
child process.)
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]