diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-11-13 17:32:03 +0100 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-11-13 17:32:03 +0100 |
commit | ff0ac5bf2b3069200d2bb5a56bc3eef0b4bcb44a (patch) | |
tree | 6778fd6eb8fb48cff51564d4110ed3bd168a3b2e /semestr-5/so/lista2/segv.c | |
parent | fa505e1e8d7f990d608144ccd97e9f960c6b8b57 (diff) |
update
Diffstat (limited to 'semestr-5/so/lista2/segv.c')
-rw-r--r-- | semestr-5/so/lista2/segv.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/semestr-5/so/lista2/segv.c b/semestr-5/so/lista2/segv.c new file mode 100644 index 0000000..6aca3ec --- /dev/null +++ b/semestr-5/so/lista2/segv.c @@ -0,0 +1,22 @@ +#include <signal.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +volatile int *p = NULL; +int x = 0; + +void segv_handler(int signum) { + char text[100]; + sprintf(text, "Segv handler! p: %p\n", p); + if (p == NULL) + p = &x; + write(STDOUT_FILENO, text, strlen(text)); +} + +int main() { + signal(SIGSEGV, segv_handler); + + *p = 1; +} |