进程扇的 例子:
/* 由一个进程派生多个子进程 */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int i;
pid_t pid;
printf("This is a example\n");
for (i=0 ;i<10; i++)
{
pid=fork();
if (pid == 0)
break;
}
printf("=============================================\n");
printf ("My pid is %ld\n",getpid());
printf ("My parent pid is %ld\n",getppid());
/* 由一个进程派生多个子进程 */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int i;
pid_t pid;
printf("This is a example\n");
for (i=0 ;i<10; i++)
{
pid=fork();
if (pid == 0)
break;
}
printf("=============================================\n");
printf ("My pid is %ld\n",getpid());
printf ("My parent pid is %ld\n",getppid());
}
进程链的例子:
/* 由父进程派生子进程,子进程再派生子进程 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
int i;
for(i=0;i<10;i++)
if ((pid = fork()) <= 0)
break;
printf("=============================================\n");
printf("My pid is %ld\n",getpid());
printf("My parent pid is %ld\n",getppid());
return 0;
}
作者:DLUTBruceZhang 发表于2013-3-10 18:24:35 原文链接
阅读:0 评论:0 查看评论