小编sub*_*ash的帖子

为什么shell和文件之间的输出不同

考虑以下程序.

main() {  
  printf("hello\n");  
  if(fork()==0)  
    printf("world\n");  
  exit(0);  
}  
Run Code Online (Sandbox Code Playgroud)

使用./a.out以下输出编译此程序:

hello  
world 
Run Code Online (Sandbox Code Playgroud)

编译此程序使用./a.out > output给出名为'output'的文件中的输出,看起来像这样:

hello  
hello  
world 
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

c unix bash fork

4
推荐指数
1
解决办法
125
查看次数

标签 统计

bash ×1

c ×1

fork ×1

unix ×1