14 Zombie Process Mode 3 4 supplement

Source: Internet
Author: User

The previous Process Control 2, describes the zombie process, and the solution of the two kinds of 4. Add two more below.

How to resolve:

3: Ignore SIGCHLD signal

Parent process settings Ignore SIGCHLD signal, child process end automatically frees process table resource

Ignore SIGCHLD signal:

Signal (SIGCHLD, sig_ign)

4: Capture SIGCHLD Signal

The parent process captures the SIGCHLD signal and executes the wait () in the Capture function code

Handling SIGCHLD Signals:

void Pfun (int nsignal)

Signal (Sigchil, Pfun)

Zombie Process:

void Testzomb ()

{

pid_t pid=fork ();

if (pid==0)

{

printf ("This is a child:%d\n", getpid ());

_exit (0);

}

Else

{

printf ("This is a parent:%d\n", getpid ());

while (1);

}

}

Rowe 3440 3110 23:04 pts/0 00:00:08./main

Rowe 3441 3440 0 23:04 pts/0 00:00:00 [main] <defunct>

The <defunct> description is a zombie process and cannot be terminated with the kill command, nor can it be manipulated.

Ignore SIGCHLD signal mode:

void Testzomb ()

{

pid_t pid=fork ();

if (pid==0)

{

printf ("This is a child:%d\n", getpid ());

_exit (0);

}

Else

{

Parent process ignores SIGCHLD

Signal (sigchld,sig_ign);

printf ("This is a parent:%d\n", getpid ());

while (1);

}

}

Capture SIGCHLD Signal mode:

void func (int sig)

{

printf ("Receive signal:%s[%d]\n", Strsignal (SIG), SIG);

Wait (NULL);

}

void Testzomb ()

{

pid_t pid=fork ();

if (pid==0)

{

printf ("This is a child:%d\n", getpid ());

_exit (0);

}

Else

{

The parent process handles the SIGCHLD

Signal (SIGCHLD,FUNC);

printf ("This is a parent:%d\n", getpid ());

while (1);

}

}

After wait ends, the process Resource table is freed by Init.

14 Zombie Process Mode 3 4 supplement

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.