1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include <mos/tasks/signal_types.h>
4#include <mos/types.h>
5#include <signal.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <unistd.h>
9
10void sigint_handler(signal_t signum)
11{
12 printf(format: "SIGINT(%d) received from PID %d, leaving...\n", (u32) signum, getpid());
13 exit(status: 0);
14}
15
16void sigsegv_handler(signal_t signum)
17{
18 printf(format: "SIGSEGV(%d) received from PID %d, leaving...\n", (u32) signum, getpid());
19 exit(status: 0);
20}
21
22int main(int argc, const char *argv[])
23{
24 MOS_UNUSED(argc);
25 MOS_UNUSED(argv);
26
27 signal(SIGINT, handler: sigint_handler);
28 printf(format: "Hello, world! (parent) PID=%d\n", getpid());
29
30 int child_pid = fork();
31 if (child_pid == 0)
32 {
33 printf(format: "Hello, world! (child) PID=%d\n", getpid());
34 while (1)
35 puts(string: "TOO BAD! SIGINT IS MISSING!");
36 }
37
38 kill(child_pid, SIGINT); // send SIGINT to child
39 printf(format: "Hehe muuurder go brrr\n");
40
41 signal(SIGSEGV, handler: sigsegv_handler);
42
43 volatile int *x = (void *) 0x01;
44 *x = 10;
45
46 puts(string: "We should never reach this point");
47 return 0;
48}
49