使用分叉时的输出窗口
Output window when using Fork
以下代码的输出是什么:
void ChildProcess(void); /* child process prototype */
void ParentProcess(void); /* parent process prototype */
int main(void)
{
pid_t pid; //stores the process ID
pid = fork(); //creates a child process of same program
if (pid == 0)
ChildProcess(); //If a child is executing a process,for it , PID will be 0
else
ParentProcess(); //The parent can have access to child process PID
return 0;
}
void ChildProcess(void)
{
for(int i=0; i< 100; i++)
cout<<"I am the child"<<endl;
}
void ParentProcess(void)
{
for(int i=0; i< 100; i++)
cout<<"I am the father"<<endl;
}
子进程和他的父进程在同一输出控制台(窗口)上打印输出?!我的意思是输出是这样的:我是父亲我是孩子我是父亲我是孩子我是父亲我是孩子
是的,它们输出到同一个控制台,所以你应该得到:
I am the child
I am the father
I am the child
I am the father
I am the child
I am the father
I am the child
I am the father
...
但你也可以有这样的东西:
I am the father
I am the child
I am the child
I am the child
I am the father
I am the father
...
顺序高度依赖于操作系统、计算机的内核数量,并且可能是非常随机的。
相关文章:
- 为什么输出窗口上没有显示输出?
- 输出窗口中消息的可视化工作室源
- 输出 c++ 窗口 wstring 日志在终端中正确
- C++/Visual Studio-如何输出到测试输出窗口
- 如何将日志记录写入Visual Studio输出窗口?
- 调整项目在Visual Studio的输出窗口中构建报告
- 使用分叉时的输出窗口
- 制作垫子类型对象的数组.输出窗口显示同一帧
- 以编程方式清除Visual Studio输出窗口
- 打印到Visual Studio中的输出窗口
- 全屏获取c ++程序的输出.它是控制台输出窗口的目标代码
- Xcode 6 在我按下输出窗口后意外退出
- 将命令提示符输出重定向到 Visual Studio 2012 中的输出窗口
- VS2013-输出窗口不显示std::cout
- 输出窗口显示三个图像,而不是一个
- 在Visual C++IDE的输出窗口上打印输出
- Visual studio 2008输出窗口停止工作
- 是否有一种简单的方法可以用可互操作的代码在CLI中清理屏幕/保持输出窗口,避免conio.h和ncurses.h
- 额外的单词出现在visualc++输出窗口
- 在Visual Studio中使用本地Windows调试器运行第一个程序。输出窗口显示大量"Cannot find or open the PDB file"