• Organization Of Asynchronous Execution Of Processes
  • Managing Threads in Linux Basic support for multithreading
  • 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
    bet37/203
    Sana10.01.2024
    Hajmi6,34 Mb.
    #134102
    1   ...   33   34   35   36   37   38   39   40   ...   203
    Bog'liq
    Linux This Book Includes 4 Manuscripts The Underground Bible

    Signal Generation
    Let's consider how to send a process signal. This uses the kill () system call.
    #include (signal.h>


    int kill (pid_t pid, // process ID
    int signum ); // signal number
    For example, sending a SIGHUP signal to a process pid that is specified at
    the command line:
    kill ( atoi ( argv [1], SIGHUP );
    Organization Of Asynchronous Execution Of
    Processes
    Consider how you can use signal processing to organize asynchronous
    process execution. As you know, calling waitpid () causes an offspring to
    execute synchronously. When to start the descendant process is
    asynchronous. It seems natural not to call waitpid () in the
    ancestor process for that descendant. But upon completion of the
    descendant process, it will turn into a zombie process.
    To avoid this, you must take advantage of the fact that the ancestor process
    receives a special SIGCHLD signal at the end of the descendant
    process. Calling waitpid () in this signal handler will remove the descendant
    process information from the process table, leaving zombies in the system.
    void clear_zombie (int signum)
    {
    waitpid (-1, NULL, 0);
    }
    struct sigaction action = {0};
    action.sa_handler = clear_zombie;
    sigaction (SIGCHLD, & action, 0);
    if ((pid = fork ()) == - 1)
    _ exit ();
    if ( pid == 0)
    {
    // descendant running asynchronously


    exit ();
    }
    else
    {
    // ancestor does not have a waitpid () call
    }
    Managing Threads in Linux
    Basic support for multithreading
    Until recently, the only multithreading support for Linux was
    the clone () system call, which made it possible to create a new process
    based on an existing one. This call is similar to the fork () call but has
    several other features.

    For the new process, you need to specify a special set of
    checkboxes that determine how resources will be distributed between
    the ancestor and the descendant. The resources that can be shared
    include address space, open file information, signal handlers. Note
    that in the traditional clone () implementation, there is no special use
    of process identifier ( pid ), ancestor ID, and some other important
    attributes

    The new process poribno set a new stack (as a consequence
    call clone () two processes can share a common memory diamond, are
    unacceptable for general use stack)
    Support clone () means implementing multithreading scheme 1: 1. The
    primary ones in the system are processes, not threads (in Linux, the
    instructions given by the kernel on which the kernel runs are called
    processes, not kernel threads). The traditional multithreading
    implementation on Linux determines that user threads are mapped to
    processes in the kernel. Therefore, it is impractical to look at the flow data
    structures 
    in 
    Linux 
    separately 

    it 
    is 
    displayed 
    with
    the same task _ struct structure as the process.



    Download 6,34 Mb.
    1   ...   33   34   35   36   37   38   39   40   ...   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