Kill a child process
After killing the daemon's subprocess, the process changes to a zombie process
14087 ? Ss 0:00 ./test4-1 14088 ? S 0:00 \_ ./test4-1 14089 ? S 0:00 \_ ./test4-1 14090 ? S 0:00 \_ ./test4-1 14091 ? S 0:00 \_ ./test4-1 14092 ? S 0:00 \_ ./test4-1 14093 ? S 0:00 \_ ./test4-1 14094 ? S 0:00 \_ ./test4-1 14095 ? S 0:00 \_ ./test4-1 14096 ? S 0:00 \_ ./test4-1 14097 ? S 0:00 \_ ./test4-1[[email protected] 04]# kill -9 14090[[email protected] 04]# ps -xf
After execution:
14087 ? Ss 0:00 ./test4-1 14088 ? S 0:00 \_ ./test4-1 14089 ? S 0:00 \_ ./test4-1 14090 ? Z 0:00 \_ [test4-1] <defunct> 14091 ? S 0:00 \_ ./test4-1 14092 ? S 0:00 \_ ./test4-1 14093 ? S 0:00 \_ ./test4-1 14094 ? S 0:00 \_ ./test4-1 14095 ? S 0:00 \_ ./test4-1 14096 ? S 0:00 \_ ./test4-1 14097 ? S 0:00 \_ ./test4-1[[email protected] 04]#
Kill the parent process
After the parent process of the daemon, the zombie process is released and normal child processes become normal processes
[[email protected] 04]# kill -9 14087[[email protected] 04]# ps -xf
The zombie process is gone.
14088 ? S 0:00 ./test4-1 14089 ? S 0:00 ./test4-1 14091 ? S 0:00 ./test4-1 14092 ? S 0:00 ./test4-1 14093 ? S 0:00 ./test4-1 14094 ? S 0:00 ./test4-1 14095 ? S 0:00 ./test4-1 14096 ? S 0:00 ./test4-1 14097 ? S 0:00 ./test4-1
Kill All Processes
Directly using the process name
pkill 进程名
Let the child process end together with the parent process
Use Prctl to listen for the deathsig of the parent process after the process is created
for (i = 0; i < 10; i++) { sleep(3); printf("new fork() process pid = %d \n", pid); pid = fork(); if (pid == 0) { prctl(PR_SET_PDEATHSIG,SIGKILL); break; }}
When the parent process dies, the child process automatically receives the signal and ends without generating a zombie process and an orphan process
14508 ? Ss 0:00 ./test4-2 14509 ? S 0:00 \_ ./test4-2 14510 ? S 0:00 \_ ./test4-2 14511 ? S 0:00 \_ ./test4-2 14512 ? S 0:00 \_ ./test4-2 14513 ? S 0:00 \_ ./test4-2 14514 ? S 0:00 \_ ./test4-2 14515 ? S 0:00 \_ ./test4-2 14516 ? S 0:00 \_ ./test4-2 14517 ? S 0:00 \_ ./test4-2 14518 ? S 0:00 \_ ./test4-2[[email protected] 04]# kill -9 14508[[email protected] 04]# ps -xf 6786 ? S 0:00 /usr/libexec/gconfd-2[[email protected] 04]# [[email protected] 04]# [[email protected] 04]#
Linux guard Service-Kill daemon