반응형
#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("--> Child Process\n");
if(execlp("ls", "ls", "-a", (char *)NULL) == -1){
perror("exelcp");
exit(1);
}
exit(0);
break;
default:
printf("--> Parent process - My PID:%d\n", (int)getpid());
break;
}
return 0;
}
반응형
'TIL > os' 카테고리의 다른 글
PIPE 양방향 통신하기 (0) | 2022.10.04 |
---|---|
wait를 이용하여 자식 프로세스의 종료를 기다리기 (0) | 2022.10.03 |
자식 프로세스 fork 하기 (0) | 2022.10.03 |
프로세스 실행 시간 체크 (0) | 2022.10.03 |
C언어 - 현재 시간을 변환하여 읽기 (0) | 2022.10.03 |