zoukankan      html  css  js  c++  java
  • Cleaning Up Children Asynchronously

    Listing 3.7 (sigchld.c) Cleaning Up Children by Handling SIGCHLD
    #include <signal.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    sig_atomic_t child_exit_status;
    void clean_up_child_process (int signal_number)
    {
    /* Clean up the child process. */
    int status;
    wait (&status);
    /* Store its exit status in a global variable. */
    child_exit_status = status;
    }
    int main ()
    {
    /* Handle SIGCHLD by calling clean_up_child_process. */
    struct sigaction sigchld_action;
    memset (&sigchld_action, 0, sizeof (sigchld_action));
    sigchld_action.sa_handler = &clean_up_child_process;
    sigaction (SIGCHLD, &sigchld_action, NULL);
    /* Now do things, including forking a child process. */
    /* ... */
    return 0;
    }

  • 相关阅读:
    POJ 2689
    NEFU 109
    HDU 2098
    NEFU 2
    NEFU 117
    NEFU 84
    POJ 1061
    NEFU116 GCD
    NEFU 115
    HDU 2099
  • 原文地址:https://www.cnblogs.com/michile/p/2890563.html
Copyright © 2011-2022 走看看