int forkprocess(void)
{
printf("forkprocess running......\r\n");
pid_tpid = 0;
intstatus;
while(1)
{
pid = fork();
if(pid < 0)
{
printf("fork error............\r\n");
exit(1);
}
if(pid == 0)
{
printf("this is child prodess return............\r\n");
return 0;
}
printf("wait child prodess........\n");
waitpid(pid, &status, 0);
printf("child prodess end........\n");
}
return 0;
}
{
printf("forkprocess running......\r\n");
pid_tpid = 0;
intstatus;
while(1)
{
pid = fork();
if(pid < 0)
{
printf("fork error............\r\n");
exit(1);
}
if(pid == 0)
{
printf("this is child prodess return............\r\n");
return 0;
}
printf("wait child prodess........\n");
waitpid(pid, &status, 0);
printf("child prodess end........\n");
}
return 0;
}
本文介绍了一个使用C语言实现的进程创建与管理示例。通过无限循环创建子进程,并等待每个子进程结束。父进程和子进程都打印了相应的状态信息。

440

被折叠的 条评论
为什么被折叠?



