On the problem of "Unix signal does not queue"

topic description

there is a simple signal sample program in "CSAPP". I compiled and ran the same code in Ubuntu, and the result was different from that given in the book, and it was different in the most important place: the signal was not queued.

clipboard.png

:

clipboard.png

according to the book, the term, Handler reaped child should only appear twice.

related codes

-sharpinclude "csapp.h"
/* $begin signal1 */
/* WARNING: This code is buggy! */

void handler1(int sig) 
{
    int olderrno = errno;

    if ((waitpid(-1, NULL, 0)) < 0)
        sio_error("waitpid error");
    Sio_puts("Handler reaped child\n");
    Sleep(1);
    errno = olderrno;
}

int main() 
{
    int i, n;
    char buf[MAXBUF];

    if (signal(SIGCHLD, handler1) == SIG_ERR)
        unix_error("signal error");

    /* Parent creates children */
    for (i = 0; i < 3; iPP) {
        if (Fork() == 0) {
            printf("Hello from child %d\n", (int)getpid());
            exit(0);
        }
    }

    /* Parent waits for terminal input and then processes it */
    if ((n = read(STDIN_FILENO, buf, sizeof(buf))) < 0)
        unix_error("read");

    printf("Parent processing input\n");
    while (1)
        ;

    exit(0);
}
/* $end signal1 */

need to modify the code

/* Parent creates children */
for (i = 0; i < 3; iPP) {
    if (Fork() == 0) {
        printf("Hello from child %d\n", (int)getpid());
        sleep(3);
        exit(0);
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c2201f-32d3b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c2201f-32d3b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?