在linux下编写一个程序实现父进程生成一个子进程,子进程不断执行另一程序(不能退出),要求用c语

在linux下编写一个程序实现父进程生成一个子进程,子进程不断执行另一程序(不能退出),要求用c语言写代码

#include <unistd.h>
#include <stdio.h>

void child_process()
{
    while (true)
    {
        printf("I am child process\n");
    }
}

int main()
{
     pid_t pid = fork();
     if (pid < 0)
     {
         printf("fork error! exit\n");
     }   
     if (pid == 0) //子进程
     {
         child_process();
         return 0;
     }   
     else //父进程
     {
         //父进程要执行的内容
     }
     return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答