Signal Processing wifexited/wexitstatus/wifsignaled for C + + wait capture

Source: Internet
Author: User

When a process is normal or abnormally terminated, the kernel sends a SIGCHLD signal like its parent process because the child process is an asynchronous event, so this signal is also the asynchronous notification that the kernel sends to that parent process. The parent process can choose to ignore the signal or provide a function that is called to execute when the signal occurs. The system default action for this signal is to ignore it.

What happens to a process that calls wait or waitpid:

    • If all of its child processes are running, it is blocked.
    • If a child process has been terminated, the waiting parent process gets to the terminating state, then the terminating state of the child process is taken back immediately.
    • If he does not have any child processes, an immediate error is returned.

Wifexited (status) is a non-0 value if the child process ends normally.
Wexitstatus (status) Gets the end code returned by the child process exit (), typically using wifexited to determine whether the macro ends properly before it can be used.
wifsignaled (status) This macro value is true if the child process ends because of a signal.
Wtermsig (status) Gets the signal code that the child process aborts because of the signal, generally uses wifsignaled to judge before using this macro.
wifstopped (status) This macro value is true if the child process is in a paused execution condition. This is generally the case only if you are using wuntraced.
Wstopsig (status) Gets the signal code that caused the child process to pause.

1     if(wifexited (status))2cout <<"normal termination, exitstatus ="<< wexitstatus (status) <<Endl;3     Else if(wifsignaled (status))4cout <<"abnormal termination, signalstatus ="<< wtermsig (status) <<Endl;5     Else if(wifstopped (status))6cout <<"Child stopped, signal number ="<< wstopsig (status) <<Endl;7     Else 8cout <<"Unknown Status:"<< status << Endl;

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.