一般在由Qte构建的系统中,有一个进程专门作为qwsServer(加-qws或其他方法),其他进程都由它来启动(不加-qws) ,基本方法是先fork,再用execl等。
贴一段我以前写过的代码:
38 void Controller::launchApp(const char* fileName)
39 {
40 if (fileName == NULL)
41 {
42 qCritical("Launch path is NULL!\n");
43 }
44
45 pid_t pid = fork();
46
47 if (pid == 0)
48 {
49 qDebug("new process forked. PID is:%d\n", getpid());
50 int result = execl(fileName, fileName, 0);
51
52 if (result < 0)
53 {
54 qCritical("failed to launch application!\n");
55 }
56 _exit(-1);
57 }
58 }