Linux guard Service-Kill daemon

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.