• Setting The Signal Layout
  • Linux: This Book Includes 4 Manuscripts. The Underground Bible to the unix operating System with Tools On Security and Kali Hacking to Understand Computer Programming, Data Science and Command Line




    Download 6,34 Mb.
    Pdf ko'rish
    bet36/203
    Sana10.01.2024
    Hajmi6,34 Mb.
    #134102
    1   ...   32   33   34   35   36   37   38   39   ...   203
    Bog'liq
    Linux This Book Includes 4 Manuscripts The Underground Bible

    Examples Of Signals
    Consider the signals by POSIX and supported in Linux ( in parentheses
    next to the name ' pit signal is given his room). By synchronous signals
    include, for example, the signal SIGSEGV (11) that generates the system
    while recording a protected area of memory .
    Asynchronous signals include:
    ❖ 
    SIGHUP (1) - a gap called ' communication (eg, user out of the
    system)
    ❖ 
    SIGINT and SIGQUIT (2,3) - program interrupt signals from the
    keyboard (generated by a user pressing Ctrl + C and Ctrl + \
    respectively)


    ❖ 
    SIGKILL ( 9) - immediate termination of the program (this signal
    cannot be changed position)

    SIGUSR 1 SIGUSR 2 (10,12) - user signals that can use
    applications
    ❖ 
    SIGTERM (15) - Offer the program to shut down (this signal,
    unlike SIGKILL, may be ignored)
    The default action for all of these signals, except for SIGSEGV, is to
    terminate the program ( an additional memory dump ( core dump ) is
    generated for SIGSEGV - a file that stores the image of the process address
    space for later analysis).
    Setting The Signal Layout
     
    A sigaction () system call is used to set the signal disposition.
    #include
    int sigaction (int signum, // signal numbe r
    struct sigaction * action, // new layout
    struct sigaction * old_action); // return the previous disposition
    The exposition is described using the sigaction structure with the following
    fields:
    ❖ 
    sa _ handler - pointer to the signal processor function
    ❖ 
    sa _ mask - the signal mask that specifies which signals will be
    blocked inside the processor
    ❖ 
    sa_flag - additional checkboxes
    Limit to zeroing sa _ mask and sa _ flag (without blocking any signal):
    struct sigaction action = {0};


    The sa _ handler field should be set as a pointer to a previously declared
    function that looks like this:
    void user_handler (int signum)
    {
    // signal processing
    }
    This feature becomes a signal processor. The signum parameter determines
    which signal is sent to the handler (the same handler can be logged for
    multiple signals by several sigaction () calls ). After logging in, the handler
    will always be called when it receives the appropriate signal:
    #include
    void sigint_handler (int signum)
    {
    // SIGINT processing
    }
    // …… ..
    action.sa_handler = sigint_handler;
    sigaction (SIGINT, & action, 0);
    If we need to organize the wait for the signal, the simplest way is to open a
    system call pause (). In this case, the process enters standby mode, from
    which it will output any signal:
    // ask the handlers for help with sigaction ()
    pause (); // wait for a signa l

    Download 6,34 Mb.
    1   ...   32   33   34   35   36   37   38   39   ...   203




    Download 6,34 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Linux: This Book Includes 4 Manuscripts. The Underground Bible to the unix operating System with Tools On Security and Kali Hacking to Understand Computer Programming, Data Science and Command Line

    Download 6,34 Mb.
    Pdf ko'rish