Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182860
  • 博文数量: 76
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 831
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-31 00:52
文章分类

全部博文(76)

文章存档

2010年(58)

2009年(18)

我的朋友

分类:

2010-03-25 17:26:51


example -- fork()





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

int main(){
    int pid1;
    int pid2;    

    printf("My 1st fork example.\n");
    printf("-----------------------\n");
    printf("-----------------------");
    if((pid1 = fork()) == 0){
        printf("I am child, my ID is %d, my parent's ID is %d.\n", pid1, getppid());
        sleep(2);
    }
    else if((pid2 = fork()) == 0)
        printf("I am another child, my real ID is %d, however, I return as %d.\n", getpid(), pid2);
    else{
        printf("I am Daddy. My children's ID is %d and %d\n", pid1, pid2);
        sleep(3);
    }
    printf("test complete.\n");
    return 0;
}


阅读(557) | 评论(0) | 转发(0) |
0

上一篇:Linux 常用函数

下一篇:daemon

给主人留下些什么吧!~~