niusouti.com

请分析以下程序。 int main() { pid_t pid; pid = fork(); if(pid==0) printf("I am the child process, my process ID is%d\n",getpid()); else printf("I am the parent process, my process ID is%d\n",getpid());} 那么,该程序正确运行后的结果是A.I am the child process, my process ID is 37

题目

请分析以下程序。 int main() { pid_t pid; pid = fork(); if(pid==0) printf("I am the child process, my process ID is%d\n",getpid()); else printf("I am the parent process, my process ID is%d\n",getpid());} 那么,该程序正确运行后的结果是

A.I am the child process, my process ID is 3744 I am the parent process, my process ID is 3987

B.I am the child process, my process ID is 3744

C.I am the parent process, my process ID is 3987

D.不输出任何信息


相似考题
更多“请分析以下程序。 int main() { pid_t pid; pid = fork(); if(pid==0) printf("I am the child pr ”相关问题
  • 第1题:

    嵌入式Linux操作系统中任务的创建过程如下,以下说法正确的是(53)。

    void main( )

    { int pid;

    pid= fork( )

    if(pid>0)

    printf("parent task");

    else if(pid= =0)

    { printf("child task") ;

    execvp ("MyTash", NULL);

    }

    }

    A.子任务的创建基于fork/exec模型

    B.子任务的创建基于spawn模型

    C.先为子任务分配内存空间,再分配相应的数据结构

    D.直接为子任务分配一个全新的地址空间,然后再将其代码装入运行


    正确答案:A
    解析:fork/exec模型和spawn模型创建任务时,都要先为新任务分配相应的数据结构,然后再为新任务分配内存空间。这两种模型的主要差别在于内存的分配方式,在fork/exec模型中,首先调用fork函数为新任务创建一份与父任务完全相同的内存空间,然后再调用exec函数装入新任务的代码,并覆盖原父任务的内容。而spawn模型则直接为子任务分配一个全新的地址空间,然后再将其代码装入运行。

  • 第2题:

    fork()执行成功返回子进程pid。


    错误

  • 第3题:

    简单绘出数字PID增量式算法程序的流程图,并与位置式PID控制算法比较,列出增量式PID控制算法的优点。


    错误

  • 第4题:

    UNIX操作系统中,fork()系统调用用于创建进程。仔细阅读、分析下列程序,假设程序正确运行并创建子进程成功,那么,输出到屏幕的正确结果是main() { pid_t pid; pid = fork(); if (pid = = 0) printf ("Hello World\n"); else if (pid >0) printf ("Hello World\n"); else printf ("Hello World\n"); }

    A.什么都没有

    B.1行Hello World

    C.2行Hello World

    D.3行Hello World


    正确答案:C

  • 第5题:

    fork()执行成功仅返回子进程pid。