我有一个 Main C 程序,它创建两个线程,每个线程都使用 system() 调用启动一个进程。一旦线程创建的任何一个进程完成操作,是否可以终止主程序?
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <sys/shm.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
extern errno;
key_t key = 1;
int *shm;
void* Start_Ether(){
printf("Creating Ethernet Process\n");
int ret = system("sudo ./Ether");
if (ret < 0){
printf("Error Starting Ethernet Process\n");
}
}
void* Start_Display(){
printf("Creating Display Process\n");
int ret = system("./Display");
if (ret < 0){
printf("Error Starting Display Process\n");
}
}
int main (int argc, char **argv)
{
pthread_t Ether, opengl;
int ret1, ret2;
printf("**********************************************\nMain Started\n**********************************************\n");
ret2 = pthread_create(&opengl, NULL, &Start_Display, NULL);
if (ret2 != 0){
printf("Error in Creating Display Thread\n");
}
ret1 = pthread_create(&Ether, NULL, &Start_Ether, NULL);
if (ret1 != 0){
printf("Error in Creating Ether Thread\n");
}
while(1){
continue;
}
return 1;
}