44 lines
642 B
C
44 lines
642 B
C
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <stdint.h>
|
|
#include <assert.h>
|
|
#include "helpers.h"
|
|
#include "helpers.c"
|
|
|
|
int x = 2, y = 3;
|
|
|
|
sigset_t quitset;
|
|
|
|
int swap(int *x, int *y)
|
|
{
|
|
sigemptyset(&quitset);
|
|
sigaddset(&quitset, SIGQUIT);
|
|
sigprocmask(SIG_BLOCK, &quitset, NULL);
|
|
|
|
int tmp = *x;
|
|
*x = *y;
|
|
*y = tmp;
|
|
|
|
sigprocmask(SIG_UNBLOCK, &quitset, NULL);
|
|
}
|
|
|
|
void sig_handler(int signo)
|
|
{
|
|
switch (signo)
|
|
{
|
|
case SIGQUIT:
|
|
printf("x=%d y=%d\n", x, y);
|
|
break;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
assert(set_signal_handler(SIGQUIT, sig_handler) == 0);
|
|
while (1)
|
|
{
|
|
swap(&x, &y);
|
|
}
|
|
} |