반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
pid_t pid;
int status;
switch(pid = fork()){
case -1 :
perror("fork");
exit(1);
break;
case 0:
printf("--> Child Process\n");
exit(3);
break;
default:
while(wait(&status) != pid)
continue;
printf("--> Parent process - My PID:%d\n", (int)getpid());
printf("Status: %d, %x\n, status, status");
//자식프로세스의 종료 상태값을 알 수 있다.
printf("Child process Exit status:%d\n", status >> 8);
break;
}
return 0;
}
반응형
'TIL > os' 카테고리의 다른 글
FIFO로 server client간 데이터 주고 받기 (0) | 2022.10.04 |
---|---|
PIPE 양방향 통신하기 (0) | 2022.10.04 |
exec를 이용하여 fork 후 자식 프로세스는 다른 프로그램 실행하기 (0) | 2022.10.03 |
자식 프로세스 fork 하기 (0) | 2022.10.03 |
프로세스 실행 시간 체크 (0) | 2022.10.03 |