天嵌 ARM开发社区

 找回密码
 注册
查看: 1523|回复: 1

用fork函数创建进程时发现了一个奇怪问题,求解答!

[复制链接]
clb 发表于 2014-12-4 16:09:21 | 显示全部楼层 |阅读模式
实验代码就是:
int main(void)                                            
{
    pid_t child;                                                                    
    if((child=fork())==-1)                                
    {
        printf("Fork Error : %s\n", strerror(errno));     
        exit(1);                                          
    }
    else                                                  
        if(child==0) // 徨序殻                           
        {                                                
            printf("I am the child process: %d\n", getpid());     
            exit(0);                                      
        }
        else
        {
            printf("I am the father process:%d\n",getpid());      
            exit(0);//return 0;                           
        }
}
执行时出现的现象就是:
clbiao@ubuntu:~/fork$ ./fork
I am the father process:4200
clbiao@ubuntu:~/fork$ I am the child process: 4201

可是我把程序交叉编译后下载进开发板运行又没有出现这样的现象,为什么?
现象正常:
# ./fork
I am the father process:4200
I am the child process: 4201
#
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-6-17 19:11 , Processed in 1.078125 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表