//Why not execute all the conditions(parent and child)?
#include<stdio.h>
#include<unistd.h>
int main(){
pid_t pid; //process-id
printf("This is where we start...\n");
pid = fork();
//For the child process
if(pid==0){
printf("This is the child process!\n");
return 1;
}
//This should have been printed
if(pid>0){
printf("This is the parent!\n");
}
//THis may/may not be printed - its ok
if(pid < 0){
printf("Fork failed!");
}
return 0;
}
子供から戻った後、親が実行されていたはずですが、これは私が取得したものです: $これは子プロセスです!「これは子プロセスです」という印刷後に実行が停止する理由は何ですか?
何が欠けていますか?どうして子ブロックだけでなく親ブロックも印刷されますか?
私は子供を待たずに終了している参照のみの問題。どちらも印刷する必要があります。 – stark
これはWindows版ですか? – stark