Chinaunix首页 | 论坛 | 博客
  • 博客访问: 279259
  • 博文数量: 109
  • 博客积分: 2116
  • 博客等级: 大尉
  • 技术积分: 1062
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-22 15:38
文章分类

全部博文(109)

文章存档

2013年(2)

2011年(16)

2010年(90)

2009年(1)

我的朋友

分类: 嵌入式

2010-08-10 11:05:31

完成一个进程实验。

 

原理:

1 进程ID

  函数:getpid, geppid

2 创建进程

  函数:fork

3 等待进程

  函数:waitpid

 

步骤:

1 宿主机下进行编辑,交叉编译。

2 开发板终端上进行程序的执行(NFS)。

 

现象:

宿主机

开发板

 

代码来自周立功:

#include

#include

#include

#include

#include

#include

 

int main(int argc, char **argv)

{

    int stat;

    pid_t child;

    printf("\nTry to create new process.\n");

    child=fork();

   

    switch(child)

    {

        case -1:

            perror("fork.\n");

            exit(EXIT_FAILURE);

        case 0:

            printf("This is child.\n");

            printf("\tchild pid is %d\n",getpid());

            printf("\tchild ppid is %d\n",getppid());

            exit(EXIT_SUCCESS);

        default:

            waitpid(child,&stat,0);

            printf("This is parent.\n");

            printf("\tparent pid is %d\n",getpid());

            printf("\tparent ppid is %d\n",getppid());

            printf("\tchild exited with %d\n",stat);

    }

    exit(EXIT_SUCCESS);

}

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

上一篇:文件和目录

下一篇:信号

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