#include <stdio.h>
#include <unistd.h>
#include <signal.h>
struct sigaction act_new;
struct sigaction act_prev;
struct sigaction act_sigusr1;
struct sigaction act_sigusr1_prev;
int resting;
void sigint_handler(int signo)
{
printf("Ctrl-C(SIGINT) received!!\n");
//printf("Press Ctrl-C again to terminate process.\n");
//sigaction(SIGINT, &act_prev, NULL);
//printf("You'll not see me anymore. bye. :(\n");
resting += 1;
resting *= -1;
}
void sigusr1_handler(int signo)
{
printf("sigusr1 signal\n");
}
int main( void)
{
pid_t pid;
pid = getpid();
act_new.sa_handler = sigint_handler;
act_sigusr1.sa_handler = sigusr1_handler;
sigemptyset( &act_new.sa_mask);
sigemptyset(&act_sigusr1.sa_mask);
printf("pid: %d\n", pid);
sigaction(SIGINT, &act_new, NULL);
sigaction(SIGUSR1, &act_sigusr1, NULL);
kill(pid, SIGUSR1);
kill(pid, SIGUSR1);
while(!resting)
{
printf( "running...\n");
sleep(1);
}
while(resting)
{
printf("Well I'll go get some rest. Ho-hum\n");
pause();
printf("Did you wake me up?\n");
}
printf("bye\n");
return (0);
}
pause 함수는 이름처럼 pause 하는 함수이다.
언제까지? 시그널이 들어올 때 까지.
키보드로 안 꺼지고 입력 받을 수 있는게 인터럽트 시그널 뿐이라서 이렇게 만들어 봤다.
예상 출력은 모르겠으면 다시 공부하시요.
'42cursus' 카테고리의 다른 글
[netpractice] level2 의식의흐름 문제풀이 (0) | 2022.07.13 |
---|---|
[netpractice] level1 의식의흐름 문제풀이 (0) | 2022.07.13 |
[minitalk] SIGUSR1 예제 (0) | 2022.03.13 |
[minitalk] sigaction 예제 (0) | 2022.03.13 |
fdf 깨달은점 2 (1) | 2022.01.25 |