#include #include #include #include #include class MyThread : public QThread { void run(); }; void MyThread::run() { printf("Thread OK.\n"); } int qt_test(int argc, char** argv) { QCoreApplication app(argc, argv); MyThread thread; thread.start(); int p[2]; char buf; pipe(p); switch (fork()) { case -1: perror("fork() failed"); case 0: printf("Child OK.\n"); write(p[1], "\0", 1); exit(0); default: break; } close(p[1]); read(p[0], &buf, 1); thread.wait(); return 0; } void* thread_run(void* arg) { printf("Thread OK.\n"); } int pure_test() { pthread_t thread; pthread_create(&thread, NULL, thread_run, NULL); int p[2]; char buf; pipe(p); switch (fork()) { case -1: perror("fork() failed"); case 0: close(p[0]); printf("Child OK.\n"); write(p[1], "\0", 1); exit(0); default: break; } close(p[1]); read(p[0], &buf, 1); pthread_join(thread, NULL); return 0; } int main(int argc, char** argv) { if (argc == 2) { if (!strcmp("qt", argv[1])) { return qt_test(argc, argv); } } return pure_test(); }