Let's say I need to run a bunch of code that is crashing, so I need to run it in another process. I usually do it like this:
pid = fork(); if (pid == -1) { std::cout << "Cant Spawn New Thread"; exit(0); } else if (pid == 0) { std::cout << "Im a child that will crash\n"; char *foo = (char *) 0xffff; std::cout << foo; exit(0); } else { std::cout << "PID: " << pid << "\n"; } do { std::cout << "Waiting for " << pid << " to finish .. \n"; pid_w = waitpid(pid,&status,0); } while (pid_w == -1);
Obviously, I can use fork in my Qt4 application, but I wonder if I can archive the same functionality with anything Qt4 provides, or in any portable way, without having to create a heap of #ifdefs architecture?
In any case, I only targeted this application with the pthread implementation, but I would like to keep everything as close to the native Qt API as possible.
I tested QThread , and segfault in the stream gives an autopsy of the entire application, and it seems that QProcess intended only to be used for spawning of completely different executable files. Any other alternatives?
c ++ qt qt4 fork
rasjani
source share