Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 24, 2019 07:02
Show Gist options
  • Save surinoel/74e0cfe6f87a08e0141fc4203b5feba2 to your computer and use it in GitHub Desktop.
Save surinoel/74e0cfe6f87a08e0141fc4203b5feba2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
int main(int argc, char **argv) {
sigset_t set, oldset;
sigemptyset(&oldset);
sigemptyset(&set);
sigaddset(&set, SIGINT);
printf("SIGINT BLOCKING........\n");
// SIG_BLOCK : 기존에 블록화된 시그널 집합에 두 번째 인수 set 시그널 집합을 추가
sigprocmask(SIG_BLOCK, &set, &oldset);
sleep(3);
printf("SIGSETMASK......\n");
// SIG_SETMASK : 이전 블록된 시그널 집합을 모두 지우고 두 번째 인수인 set 시그널 집합으로 설정
sigprocmask(SIG_SETMASK, &oldset, NULL);
while(1) {
sleep(1);
}
return 0;
}
#if 0
tmpset을 통해서 oldset에 SIGINT를 등록한 후 마지막에 교체하는 예제
결국에는 oldset이라는 것은 이전 블록된 시그널 내용들을 넣어주게
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
/*
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
*/
int main(int argc, char **argv)
{
sigset_t set, oldset, tmpset;
sigemptyset(&set);
sigemptyset(&oldset);
sigemptyset(&tmpset);
sigaddset(&tmpset, SIGINT);
if(sigprocmask(SIG_BLOCK, &tmpset, NULL) < 0) {
perror("sigprocmask");
return -1;
}
printf("change Empty set....\n");
if(sigprocmask(SIG_SETMASK, &set, &oldset) < 0) {
perror("sigprocmask");
return -1;
}
sleep(3);
printf("change Old set....\n");
if(sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) {
perror("sigprocmask");
return -1;
}
while(1) {
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment