X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/874b3b5a74d815aa91f325e5573052a3c8ce1d39..c6de44b989e9d7286337e4cbf4d82d919f9120e6:/lunaix-os/kernel/demos/signal_demo.c diff --git a/lunaix-os/kernel/demos/signal_demo.c b/lunaix-os/kernel/demos/signal_demo.c index e5f9533..3878a18 100644 --- a/lunaix-os/kernel/demos/signal_demo.c +++ b/lunaix-os/kernel/demos/signal_demo.c @@ -1,23 +1,21 @@ +#include #include -#include #include #include -#include #include - -LOG_MODULE("SIGDEMO") +#include void __USER__ sigchild_handler(int signum) { - kprintf(KINFO "SIGCHLD received\n"); + printf("SIGCHLD received\n"); } void __USER__ sigsegv_handler(int signum) { pid_t pid = getpid(); - kprintf(KWARN "SIGSEGV received on process %d\n", pid); + printf("SIGSEGV received on process %d\n", pid); _exit(signum); } @@ -25,13 +23,9 @@ void __USER__ sigalrm_handler(int signum) { pid_t pid = getpid(); - kprintf(KWARN "I, pid %d, have received an alarm!\n", pid); + printf("I, pid %d, have received an alarm!\n", pid); } -// FIXME: Race condition with signal (though rare!) -// For some reason, there is a chance that iret in soft_iret path -// get unhappy when return from signal handler. Investigation is needed! - void __USER__ _signal_demo_main() { @@ -44,7 +38,7 @@ _signal_demo_main() int status; pid_t p = 0; - kprintf(KINFO "Child sleep 3s, parent pause.\n"); + printf("Child sleep 3s, parent pause.\n"); if (!fork()) { sleep(3); _exit(0); @@ -52,7 +46,7 @@ _signal_demo_main() pause(); - kprintf("Parent resumed on SIGCHILD\n"); + printf("Parent resumed on SIGCHILD\n"); for (int i = 0; i < 5; i++) { pid_t pid = 0; @@ -62,26 +56,22 @@ _signal_demo_main() if (i == 3) { i = *(int*)0xdeadc0de; // seg fault! } - kprintf(KINFO "%d\n", i); + printf("%d\n", i); _exit(0); } - kprintf(KINFO "Forked %d\n", pid); + printf("Forked %d\n", pid); } while ((p = wait(&status)) >= 0) { short code = WEXITSTATUS(status); if (WIFSIGNALED(status)) { - kprintf(KINFO "Process %d terminated by signal, exit_code: %d\n", - p, - code); + printf("Process %d terminated by signal, exit_code: %d\n", p, code); } else if (WIFEXITED(status)) { - kprintf(KINFO "Process %d exited with code %d\n", p, code); + printf("Process %d exited with code %d\n", p, code); } else { - kprintf(KWARN "Process %d aborted with code %d\n", p, code); + printf("Process %d aborted with code %d\n", p, code); } } - kprintf("done\n"); - - _exit(0); + printf("done\n"); } \ No newline at end of file