A mirror of Man pages
Go to file
Michael Kerrisk b892d64f4f signalfd.2: Rewrite the text on epoll semantics
I also verified the behavior reported by Andrew Clayton
with the program below.

$ ./epoll_signalfd
PID of parent: 5661
PID of child:  5662
epoll_wait() returned 0
PID 5662: got signal 10
Successfully read signal, even though epoll_wait() didn't say FD was ready!

8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----
/* epoll_signalfd.c */

#include <sys/signalfd.h>
#include <signal.h>
#include <sys/epoll.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                        } while (0)

static void
signalTest(int sfd, int epfd)
{
    struct signalfd_siginfo fdsi;
    struct epoll_event rev;
    int ready;
    ssize_t s;

    usleep(50000);
    ready = epoll_wait(epfd, &rev, 1, 0);
    if (ready == -1)
        errExit("epoll_wait");

    printf("epoll_wait() returned %d\n", ready);

    s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
    if (s != sizeof(struct signalfd_siginfo))
        errExit("read");

    printf("PID %ld: got signal %d\n", (long) getpid(), fdsi.ssi_signo);

    if (ready == 0 && s > 0)
        printf("Successfully read signal, even though epoll_wait() "
                "didn't say FD was ready!\n");
}

int
main(int argc, char *argv[])
{
    struct epoll_event ev;
    sigset_t mask;
    int sfd, epfd;

    sigfillset(&mask);
    sigdelset(&mask, SIGINT);

    if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
        errExit("sigprocmask");

    sfd = signalfd(-1, &mask, SFD_NONBLOCK);
    if (sfd == -1)
        errExit("signalfd");

    epfd = epoll_create(5);
    if (epfd == -1)
        errExit("epoll_create");

    ev.data.fd = sfd;
    ev.events = EPOLLIN;
    if (epoll_ctl(epfd, EPOLL_CTL_ADD, sfd, &ev) == -1)
        errExit("epoll_ctl");

    switch (fork()) {
    case -1:
        errExit("fork");
    case 0:
        printf("PID of child:  %ld\n", (long) getpid());
        raise(SIGUSR1);
        signalTest(sfd, epfd);
        break;
    default:
        printf("PID of parent: %ld\n", (long) getpid());
        wait(NULL);
        break;
    }

    exit(EXIT_SUCCESS);
}
8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-09-23 16:48:36 +02:00
man1 localedef.1: describe recently added options 2019-08-26 23:26:15 +02:00
man2 signalfd.2: Rewrite the text on epoll semantics 2019-09-23 16:48:36 +02:00
man3 strtok.3: Correct description of use of 'saveptr' argument in strtok_r() 2019-09-23 15:57:11 +02:00
man4 smartpqi.4: wfix 2019-08-27 00:01:24 +02:00
man5 resolv.conf.5: srcfix 2019-09-13 16:01:58 +02:00
man6 intro.6: wfix 2017-08-25 21:41:03 +02:00
man7 mount_namespaces.7: SEE ALSO: refer to example in pivot_root(2) 2019-09-23 13:11:19 +02:00
man8 ld.so.8: tfix 2019-08-26 23:14:49 +02:00
scripts scripts: mark them executable 2018-05-31 21:34:32 +02:00
CONTRIBUTING CONTRIBUTING: New file with some starting tips on how to contribute 2019-09-13 15:59:08 +02:00
Changes Start of man-pages-5.03: updating Changes and Changes.old 2019-08-02 10:31:40 +02:00
Changes.old Changes.old: Fixes to 5.02 log 2019-08-02 11:26:00 +02:00
Makefile Makefile: Remove a redundant comment 2017-11-20 10:38:10 +01:00
README README: tfix 2017-05-13 20:14:15 +02:00
man-pages-5.03.Announce Start of man-pages-5.03: updating .Announce and .lsm files 2019-08-02 10:31:40 +02:00
man-pages-5.03.lsm Start of man-pages-5.03: updating .Announce and .lsm files 2019-08-02 10:31:40 +02:00

README

This package contains Linux man pages for sections 1 through 8.  Some
more information is given in the 'man-pages-x.y.Announce' file.

Installing and uninstalling
===========================
"make install" will copy these man pages to /usr/share/man/man[1-8].

To install to a path different from /usr, use
"make install prefix=/install/path".

"make remove" or "make uninstall" will remove any man page in this
distribution from its destination.  Use with caution, and remember to
use "prefix" if desired, as with the "install" target.

"make" or "make all" will perform "make uninstall" followed by "make
install".

Man page overlap and duplication
================================
Note that sometimes these pages are duplicates of pages also distributed
in other packages.  This has been reported about:

man page                also found in
-------------------------------------
resolver.3              bind-utils, bind9utils
resolv.conf.5           "
passwd.5                shadow, passwd
mailaddr.7              ?

Copyrights
==========
See the 'man-pages-x.y.Announce' file.

Homepage
========
For much more about the Linux man-pages project, see
http://www.kernel.org/doc/man-pages/index.html.