반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
int main() {
pid_t pid;
switch (pid = fork()){
case -1 :
perror("fork");
exit(1);
break;
case 0:
printf("Childe Process - My PID:%d, My Parent's PID:%d\n", (int)getpid(), (int)getppid());
break;
default :
printf("Parent process - My PID:%d, My Parent's PID:%d, My Child's PID:%d\n", (int)getpid(), (int)getppid(), (int)pid);
break;
}
printf("End of fork\n");
return 0;
}
반응형
'TIL > os' 카테고리의 다른 글
wait를 이용하여 자식 프로세스의 종료를 기다리기 (0) | 2022.10.03 |
---|---|
exec를 이용하여 fork 후 자식 프로세스는 다른 프로그램 실행하기 (0) | 2022.10.03 |
프로세스 실행 시간 체크 (0) | 2022.10.03 |
C언어 - 현재 시간을 변환하여 읽기 (0) | 2022.10.03 |
[Docker] 라이프 사이클 (0) | 2022.09.18 |