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);
31 // FIXME: Race condition with signal (though rare!)
32 // For some reason, there is a chance that iret in soft_iret path
33 // get unhappy when return from signal handler. Investigation is needed!
38 signal(_SIGCHLD, sigchild_handler);
39 signal(_SIGSEGV, sigsegv_handler);
40 signal(_SIGALRM, sigalrm_handler);
47 kprintf(KINFO "Child sleep 3s, parent pause.\n");
55 kprintf("Parent resumed on SIGCHILD\n");
57 for (int i = 0; i < 5; i++) {
59 if (!(pid = fork())) {
60 signal(_SIGSEGV, sigsegv_handler);
63 i = *(int*)0xdeadc0de; // seg fault!
65 kprintf(KINFO "%d\n", i);
68 kprintf(KINFO "Forked %d\n", pid);
71 while ((p = wait(&status)) >= 0) {
72 short code = WEXITSTATUS(status);
73 if (WIFSIGNALED(status)) {
74 kprintf(KINFO "Process %d terminated by signal, exit_code: %d\n",
77 } else if (WIFEXITED(status)) {
78 kprintf(KINFO "Process %d exited with code %d\n", p, code);
80 kprintf(KWARN "Process %d aborted with code %d\n", p, code);