#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
printf("开始加载\n");
int a = fork();
if(a==0)
{
system("./t1");
//execl("./t1","t1",NULL);
}
int a1 = fork();
if(a1==0)
{
system("./t2");
}
int a2 = fork();
if(a2==0)
{
system("./t3");
}
printf("加载完毕\n");
while (1);
return 0;
}
t1
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int i = 0;
while (1)
{
i++;
printf("1号程序:%d\n",i);
sleep(2);
}
return 0;
}
结果:
创建一个子进程 让子进程实现循环任务