这是一个程序系统
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("./client &");
printf("WE are in main program\n");
printf("WE are in main program\n");
printf("WE are in main program\n");
printf("WE are in main program\n");
printf("WE are in main program\n");
return 0;
}
我是客户
#include <stdio.h>
int main()
{
printf("We are in background process\n");
do {
//doing some process on message queue to receive messages
} while (1);
return 0;
}
如何获取的输出
/从linux终端运行的系统,如下所示
We are in background process
WE are in main program
WE are in main program
WE are in main program
WE are in main program
WE are in main program
有谁能更清楚地解释一下吗?
最佳答案
也许你可以看看这个并激励自己。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int pid;
int status;
pid = fork();
if (pid == -1)
{
// handle error
}
if (pid == 0)
{
// exec child process
execl("./client", "client", NULL);
}
else
{
wait(&status);
}
printf("WE are in main program\n");
printf("WE are in main program\n");
printf("WE are in main program\n");
printf("WE are in main program\n");
printf("WE are in main program\n");
return 0;
}