1 #include <lunaix/lunistd.h>
2 #include <lunaix/proc.h>
3 #include <lunaix/signal.h>
4 #include <lunaix/spike.h>
5 #include <lunaix/syslog.h>
6 #include <lunaix/types.h>
11 sigchild_handler(int signum)
13 kprintf(KINFO "SIGCHLD received\n");
17 sigsegv_handler(int signum)
20 kprintf(KWARN "SIGSEGV received on process %d\n", pid);
25 sigalrm_handler(int signum)
28 kprintf(KWARN "I, pid %d, have received an alarm!\n", pid);
34 signal(_SIGCHLD, sigchild_handler);
35 signal(_SIGSEGV, sigsegv_handler);
36 signal(_SIGALRM, sigalrm_handler);
43 kprintf(KINFO "Child sleep 3s, parent pause.\n");
51 kprintf("Parent resumed on SIGCHILD\n");
53 for (int i = 0; i < 5; i++) {
55 if (!(pid = fork())) {
56 signal(_SIGSEGV, sigsegv_handler);
59 i = *(int*)0xdeadc0de; // seg fault!
61 kprintf(KINFO "%d\n", i);
64 kprintf(KINFO "Forked %d\n", pid);
67 while ((p = wait(&status)) >= 0) {
68 short code = WEXITSTATUS(status);
69 if (WIFSIGNALED(status)) {
70 kprintf(KINFO "Process %d terminated by signal, exit_code: %d\n",
73 } else if (WIFEXITED(status)) {
74 kprintf(KINFO "Process %d exited with code %d\n", p, code);
76 kprintf(KWARN "Process %d aborted with code %d\n", p, code);