aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista2/segv.c
blob: 6aca3ec806b995ad5ef91400498551fff69f772b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
}