Skip to content

Commit

Permalink
day09
Browse files Browse the repository at this point in the history
  • Loading branch information
geunoo committed May 10, 2023
1 parent 30cf1ec commit a680db5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ex10-03.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ int main() {

void int_handle(int signum) {
printf("SIGINT:%d\n", signum);
printf("int_handle called %d times\n", +num);
printf("int_handle called %d times\n", +num)
}
28 changes: 28 additions & 0 deletions ex10-04.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

void int_handle(int);

int num = 0;

int main() {
static struct sigaction act;
act.sa_handler = int_handle;
sigfillset(&(act.sa_mask));
sigaction(SIGINT, &act, NULL);

while(1){
printf("I'm sleepy\n");
sleep(1);
if(num >= 3)
exit(0);
}
}

void int_handle(int signum) {
printf("SIGINT:%d\n", signum);
printf("int_handle called %d times\n", +num)
}

Binary file added ex10-05
Binary file not shown.
22 changes: 22 additions & 0 deletions ex10-05.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
sigset_t set;
int count = 3;

sigemptyset(&set);
sigaddset(&set, SIGINT);

sigprocmask(SIG_BLOCK, &set, NULL);

while(count) {
printf("don't disturb me (%d)\n", count--);
sleep(1);
}

sigprocmask(SIG_UNBLOCK, &set, NULL);
printf("you did not disturb me!!\n");
}
Binary file added ex10-05_1
Binary file not shown.
23 changes: 23 additions & 0 deletions ex10-05_1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
sigset_t set;
int count = 5;

sigemptyset(&set);
sigfillset(&set);

sigprocmask(SIG_BLOCK, &set, NULL);

while(count) {
printf("don't disturb me (%d)\n", count--);
sleep(1);
}
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigprocmask(SIG_UNBLOCK, &set, NULL);
printf("disturb me!!\n");
}

0 comments on commit a680db5

Please sign in to comment.