TIL/os
exec를 이용하여 fork 후 자식 프로세스는 다른 프로그램 실행하기
DingCoDing
2022. 10. 3. 23:16
반응형
#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;
}
반응형