OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [signal/] [sigchld.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdlib.h>
2
#include <string.h>
3
#include <errno.h>
4
#include <stdio.h>
5
#include <sys/signal.h>
6
#include <sys/wait.h>
7
#include <unistd.h>
8
 
9
 
10
void test_handler(int signo)
11
{
12
    write(1, "caught SIGCHLD\n", 15);
13
    return;
14
}
15
 
16
 
17
int main(void)
18
{
19
    pid_t mypid;
20
    struct sigaction siga;
21
    static sigset_t sigset;
22
 
23
    /* Set up sighandling */
24
    sigfillset(&sigset);
25
    siga.sa_handler = test_handler;
26
    siga.sa_mask = sigset;
27
    siga.sa_flags = 0;
28
    if (sigaction(SIGCHLD, &siga, (struct sigaction *)NULL) != 0) {
29
        fprintf(stderr, "sigaction choked: %s!", strerror(errno));
30
        exit(EXIT_FAILURE);
31
    }
32
 
33
 
34
    /* Setup a child process to exercise the sig handling for us */
35
    mypid = getpid();
36
    if (fork() == 0) {
37
        int i;
38
 
39
        for (i=0; i < 3; i++) {
40
            sleep(2);
41
            kill(mypid, SIGCHLD);
42
        }
43
        _exit(EXIT_SUCCESS);
44
    }
45
 
46
 
47
    /* Wait for signals */
48
    write(1, "waiting for a SIGCHLD\n",22);
49
    for(;;) {
50
        sleep(10);
51
        if (waitpid(-1, NULL, WNOHANG | WUNTRACED) > 0)
52
            break;
53
        write(1, "after sleep\n", 12);
54
    }
55
 
56
    printf("Bye-bye!  All done!\n");
57
    return 0;
58
}
59
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.