diff --git a/test/Makefile b/test/Makefile index 42a861768..a7ade8b46 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,6 +4,7 @@ SRCS += test-shmem-async.c SRCS += test-shmem-three-async.c SRCS += test-pipe-async.c SRCS += test-vdso.c +SRCS += test-sigaction.c SRCS-TH += test-pthreads.c OBJS-TH += $(patsubst %.c,%.o,$(SRCS-TH)) diff --git a/test/test-sigaction.c b/test/test-sigaction.c new file mode 100644 index 000000000..7b074d34c --- /dev/null +++ b/test/test-sigaction.c @@ -0,0 +1,53 @@ +#include +#include + +#include + +#include +#include + +static void forked_handler(int sig) +{ + printf("%d: %s\n", getpid(), __func__); +} + +static void primary_handler(int sig) +{ + printf("%d: %s\n", getpid(), __func__); +} + +int main(int argc, char *argv[]) +{ + struct sigaction act; + int pid; + + printf("%s pid %d\n", argv[0], getpid()); + + pid = fork(); + if (pid < 0) { + exit(-1); + } else if (pid == 0) { + act.sa_handler = forked_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGTSTP, &act, 0); + + while (1) { + kill(getppid(), SIGTSTP); + kill(getpid(), SIGTSTP); + sleep(1); + } + + } else { + act.sa_handler = primary_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGTSTP, &act, 0); + + while (1) { + sleep(1); + } + } + + return 0; +}