OS/Linux
좀비 프로세스 만들기
LukeHan1128
2020. 12. 14. 20:00
반응형
테스트를 위해 좀비 프로세스가 필요한 상황이였다.
코드
fine name : zombie.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void)
{
pid_t pid;
int status;
if ((pid = fork()) < 0) {
perror("fork");
exit(1);
}
/* Child */
if (pid == 0)
exit(0);
/* Parent
* Gives you time to observe the zombie using ps(1) ... */
sleep(100);
/* ... and after that, parent wait(2)s its child's
* exit status, and prints a relevant message. */
pid = wait(&status);
if (WIFEXITED(status))
fprintf(stderr, "\n\t[%d]\tProcess %d exited with status %d.\n",
(int) getpid(), pid, WEXITSTATUS(status));
return 0;
}
빌드
# install build package
sudo apt-get install build-essential
# build
cc zombie.c -o zombie
# run
./zombie
참고
- https://stackoverflow.com/questions/25172425/create-zombie-process
- https://vitux.com/how-to-create-a-dummy-zombie-process-in-ubuntu/
반응형