首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

UNIX过程的创建,进程链和进程扇

2013-03-13 
UNIX进程的创建,进程链和进程扇进程扇的 例子:/* 由一个进程派生多个子进程 */#include stdlib.h#includ

UNIX进程的创建,进程链和进程扇
进程扇的 例子:

/* 由一个进程派生多个子进程 */

#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;

}

热点排行