一个关于linux fork()的笔试题
14 If one compiled and ran the following C Program in linux. Which of the descriptions below is(are) correct, assuming that the fork() syscall will not fail?
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int i = 1;
if(!fork()) i++;
printf("%d\n", i);
if(!fork()) i++;
printf("%d\n", i);
return 0;
}
A. The output will include number "1" exactly two times;
B. The output will include number "2" exactly two times;
C. Number "3" will always be last outputted;
D. Number "1" will always be ahead of number "3" in output;
E. It is possible that no number "3" in output, because "i++" is not an atomic operation.
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int i = 1;
if(!fork()) i++;
printf("%d\n", i);
if(!fork()) i++;
printf("%d\n", i);
return 0;
}
A. The output will include number "1" exactly two times;
B. The output will include number "2" exactly two times;
C. Number "3" will always be last outputted;
D. Number "1" will always be ahead of number "3" in output;
E. It is possible that no number "3" in output, because "i++" is not an atomic operation.
...全文
相关推荐
百度2014校园招聘笔试试题-研发工程师笔试题.docx
以上是百度2014研发工程师笔试题中涉及的主要知识点,包括计算机存储层次、Unix/Linux进程管理和网络通信的socket编程。
关于连续使用fork()到底产生多少个子进程问题的实践
关于连续使用fork()到底产生多少个子进程问题的实践 原问题来自网上的提问,近来也有不少相关的IT公司笔试题要求在使用fork()多次的情况下写出输出某个字符串的次数。针对这个问题,不少网友有不同的看法。我对于这个问题的探究主要放在fork()到底产生多少个子进程这个问题上。 实验环境:64-Ubuntu/Linuxversion 3.13.0-37-generic/gcc version
百度2014校园招聘笔试试题-研发工程师笔试题(济南站).doc
接下来是关于**Unix/Linux系统中的僵尸进程**。当一个进程结束时,其资源大部分会被释放,但进程描述符仍然存在于系统中,成为僵尸进程。
IT笔试资源
Unix/Linux系统中僵尸进程- **产生原因**:当一个进程通过`exit()`结束自身后,如果没有正确处理子进程结束后的清理工作,就会产生僵尸进程。
简单掌握Linux系统中fork()函数创建子进程的用法
"简单掌握Linux系统中fork()函数创建子进程的用法"在Linux系统编程中,`fork()`函数是一个非常关键的系统调用,它允许一个已经存在的进程(父进程)创建一个新的进程(子进程)。`f


