Aller au contenu | Aller au menu | Rechercher

Blog | Budget | Gallery | Sys Info |

LibChildControl - a thread management library

About LibChildControl

This library creates a thread to manage child process and restart them on failure.

Usage

Function register_child add a new child; child_id is the child identifier, preinit function is called by the main process before forking the child process, postinit function is called by the main process after forking the child process, process function is called by child processs (this becomes its main function), term is called called by child signal handler on SIGINT, SIGQUIT, or SIGTERM and data is a generic pointer for all those functions containing private child data.

Function kill_all_children kills all children using signal sig and exit returning code cause.

Function create_queue_task() creates queue task named name, with the ability to process at max a number of nb_sub_tasks sub-tasks, at real-time priority set to priority, composed of nb_sub_queues threads, assigns to cpu_list. A function init can initialize internal structures and memories. A pointer of queue_task_t is returned overwise NULL.

Examples

An examples of the use of LibChildControl.

int child_process (void *data)
{
    int id = *(int *)data;
    int delay = (id + 1) * 1000;

    printf ("TEST: Start child %d.\n", id);

    int i;
    for (i = 0; i < nb_loops; i++) {

        printf ("TEST: Child %d is working (loop %d/%d)\n", id, i + 1, nb_loops);

        int j;
        float r = 0;
        for (j = 0; j < 100 * id; j++) {
            float x = 0;
            do
                x = (float) rand () / ((float)RAND_MAX + 1);
            while (x == 0);
            float y = (float) rand () / ((float)RAND_MAX + 1);
            float z = sqrtf (-2. * logf (x)) * cosf (2 * M_PI * y);
            r += z * (1 << 31);
            usleep (1000);
        }
    }
    
    kill (getpid (), SIGTERM);

    return 0;
}


int child_term (void *data)
{
    int id = *(int *)data;
    printf ("TEST: Child %d is dieing.\n", id);
    return 0;
}

#define nb_children 2
#define nb_loops    10

int main (int argc, char *argv[])
{
    int d[nb_children];
    int i;
    for (i = 0; i < nb_children; i++) {
        d[i] = i + 1;
        register_child (i + 1, NULL, NULL, child_process, child_term, (void *)(d + i));
    }

    sleep (100);

    return 0;
}

Screen-shot

Shell view

Downloads

Source packages

Debian packages

Requirements

This library only need a C compiler to be build.

To install, one only needs to

Changelogs

LibChildControl 1.4.1 (Tue, 03 Jun 2014 08:58:31 +0200)

LibChildControl 1.4.0 (Tue, 29 Apr 2014 09:16:50 +0200)

Page créee/modifié le 28 avril 2014.

Envoyez tout commentaire à Laurent Mazet

Ce site fonctionne avec des logiciels libres tels que Debian GNU/Linux, Apache, MySQL et PHP

Valid XHTML 1.1 Valid CSS!