Process Termination

void exit(int status);  //status: 상태 종료 값 반환. 정상 종료일 떄 0을 인자로 넣음.
void _Exit(int status);

int atexit(void (*func)(void));  //exit handler: cleanup 동작 정의. 등록된 순서 역순으로 동작

// echo $?   종료된 process 상태 정보 확인

pid_t wait(int *statloc);  //statloc: exit(status)에서 반환되는 status 값 넣음

WIFEXITED(status)  //child가 남긴 status 반환
WEXITSTATUS(status)  //child가 남긴 status가 0인지 아닌지 확인

pid_t waitpid(pid_t pid, int *statloc, int options);
//options: WCONTINUED, WNOHANG: 바로 0리턴, WUNTRACED: 정지된 child의 status
//pid == -1 : 아무 child 하나 기다림. wait이랑 같은 동작
//pid > 0 : 특정 child 기다림
//pid == 0 : pgid가 같은 child 중 하나 기다림
//pid < 0 : pgid가 인자로 들어온 값의 절대 값에 해당하는 child 기다림. ex) pid == -2 일때 pgid == 2인 child 기다림

Zombie Process

Untitled

Orphan Process

Untitled