1 #include <lunaix/lunistd.h>
2 #include <lunaix/proc.h>
3 #include <lunaix/signal.h>
4 #include <lunaix/spike.h>
5 #include <lunaix/types.h>
6 #include <ulibc/stdio.h>
9 sigchild_handler(int signum)
11 printf("SIGCHLD received\n");
15 sigsegv_handler(int signum)
18 printf("SIGSEGV received on process %d\n", pid);
23 sigalrm_handler(int signum)
26 printf("I, pid %d, have received an alarm!\n", pid);
32 signal(_SIGCHLD, sigchild_handler);
33 signal(_SIGSEGV, sigsegv_handler);
34 signal(_SIGALRM, sigalrm_handler);
41 printf("Child sleep 3s, parent pause.\n");
49 printf("Parent resumed on SIGCHILD\n");
51 for (int i = 0; i < 5; i++) {
53 if (!(pid = fork())) {
54 signal(_SIGSEGV, sigsegv_handler);
57 i = *(int*)0xdeadc0de; // seg fault!
62 printf("Forked %d\n", pid);
65 while ((p = wait(&status)) >= 0) {
66 short code = WEXITSTATUS(status);
67 if (WIFSIGNALED(status)) {
68 printf("Process %d terminated by signal, exit_code: %d\n", p, code);
69 } else if (WIFEXITED(status)) {
70 printf("Process %d exited with code %d\n", p, code);
72 printf("Process %d aborted with code %d\n", p, code);