Re: Gtkmm and fork()
- From: michi7x7 <mailing-lists michi7x7 de>
- To: gtkmm-list gnome org
- Subject: Re: Gtkmm and fork()
- Date: Sat, 10 Apr 2010 15:31:07 +0200
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...
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]