1
저는 fork
과 exec
을 처음 사용하고 다음 프로그램을 시도했습니다.자식 프로세스의 반환 값
프로그램 1 :
int main(int argc, char *argv[]){
pid_t pid;
int status;
pid = fork();
if(pid == 0){
printf("new process");
execv("p1",argv);
}
else{
pid_t pr = wait(&status);// I am trying to get the exit value
// of the sub process.
printf("the child process exit with %d",status);
printf("father still running\n");
}
}
프로그램 2 :
int main(){
std::cout<<"I am the new thread"<<std::endl;
sleep(1);
std::cout<<"after 1 second"<<std::endl;
exit(1);
}
는 내가 처음 프로그램을 실행하고 출력은 "256 자식 프로세스 종료"입니다. 1
대신에 결과가 256
인 이유는 무엇입니까? exit(1)
을 exit(2)
으로 변경하면 결과는 512
이됩니다. 그 이유는 무엇입니까?