aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista2/segv.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestr-5/so/lista2/segv.c')
-rw-r--r--semestr-5/so/lista2/segv.c22
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;
+}