当前位置: 技术问答>linux和unix
fork奇怪问题
来源: 互联网 发布时间:2017-04-04
本文导语: 在学习linux中的著名函数fork时出现一个奇怪的问题:粘贴代码如下: #include #include /* 这个程序在虚拟机ubuntu上跑的结果令人费解: This is the main process's begining! This is ths main proccess's begining!This is the child proce...
在学习linux中的著名函数fork时出现一个奇怪的问题:粘贴代码如下:
#include
#include
/*
这个程序在虚拟机ubuntu上跑的结果令人费解:
This is the main process's begining!
This is ths main proccess's begining!This is the child process
This is the main process's end!
This is ths main proccess's begining!This is the father process!
This is the main process's end!
明明两个printf都在一块儿的,为什么运行的时候却只有一个打印了呢?
*/
int main()
{
int pid;
printf("This is the main process's begining!n");
printf("This is ths main proccess's begining!");//若改为printf("This is ths main proccess's begining!n");运行结果又不一样!!!!!
if((pid=fork())
#include
#include
/*
这个程序在虚拟机ubuntu上跑的结果令人费解:
This is the main process's begining!
This is ths main proccess's begining!This is the child process
This is the main process's end!
This is ths main proccess's begining!This is the father process!
This is the main process's end!
明明两个printf都在一块儿的,为什么运行的时候却只有一个打印了呢?
*/
int main()
{
int pid;
printf("This is the main process's begining!n");
printf("This is ths main proccess's begining!");//若改为printf("This is ths main proccess's begining!n");运行结果又不一样!!!!!
if((pid=fork())