목록Linux/TCP IP Socket Programming (19)
min's devlog
select() 동시에 여러개의 프로세스를 처리하는 함수 select()는 SA_RESTART 에 의해 재시작되지 않는 예외적인 함수이다 따라서, SA_RESTART 플랙을 설정해도, select()함수가 시그널에 의해 인터럽트 되었는가를 검사하는게 안전하다. SA_NODEFER 옵션 act.sa_flags = SA_RESTART | SA_NODEFER 중복도착한 시그널의 수 만큼 시그널 핸들러를 처리한다. #include #include #include #include #include #include //시그널 핸들러 void catch_sigint(int signum){ int count; printf("\n(count=%d) CTRL-C pressed!\n",count); return; } int ..

시스템콜 (read) 수행중의 시그널처리 #include #include #include #include #include #include //시그널 핸들러 void catch_sigint(int signum){ int count; printf("\n(count=%d) CTRL-C pressed!\n",count); return; } int main(int argc,char*argv[]){ struct sigaction act; //sigaction 구조체 sigset_t masksets; int i; int count; char buf[10]; sigfillset(&masksets); //시그널 핸들러 설치 act.sa_handler=catch_sigint; //시그널 핸들러가 실행되는 동안 모든 시그널..

read 수행중의 시그널처리 시그널 핸들러 void catch_sigint(int signum){ int count; printf("\n(count=%d) CTRL-C pressed!\n",count); return; } int main(int argc,char*argv[]){ struct sigaction act; //sigaction 구조체 sigset_t masksets; int i; int count; char buf[10]; sigfillset(&masksets); //시그널 핸들러 설치 act.sa_handler=catch_sigint; //시그널 핸들러가 실행되는 동안 모든 시그널을 블록함 act.sa_mask=masksets; act.sa_flags=0; sigaction(SIGINT,&a..

- SIGINT 처리 예 (유닉스에서 ctrl c 누를 경우 프로세스가 죽음. 이 때 프로그램이 어떻게 시그널로 처리되는지) - 시스템 콜 수행중의 시그널 처리 - 중복 블록된 시그널 처리 - SIGALARM에 의한 read()의 timeout 예 SIGINT 시그널의 기본동작 프로세스를 종료 SIGINT 시그널이 발생하면 종료되는 대신, catch_sigint() 함수를 호출하는 프로그램 파일명 : catch_sin3.c 컴파일: gcc -o catch_sin3 catch_sin3.c 실행 : catch_sin3 //헤더파일 #include #include #include #include #include //global변수이면서(=전역변수-프로그램의 어느 곳에서라도 참조할 수 있는 변수) & syste..

Signal Handler 시그널이 발생했을 때 어떻게 그 시그널을 처리할 것인가 시그널 핸들러 시그널 수신 시 호출할 함수(시그널핸들러)를 등록한다. signal(SINALARM, tcp_timer); alarm을 10초 설정해놨다고 치면, SIGALARM 이 발생하는 10초동안 다른일 하다가 끝나면 tcp_timer로 점프 signal(SIGINT, SIG_IGN) SIGINT가 발생하면 ctrl-c로 프로세스를 종료시킬 수 있다. 이를 종료되지 않게 막는게 (sig_ignore)SIG_ING ->SIGINT가 발생하면 SIG_IGN이라는 이벤트가 발생하도록 한다. 사용자가 정의한 함수로 점프하거나, 시그널을 무시하거나, 일반적으론 종료가 되게 한다. (함수-이벤트 나열은 옛날 표기법임) 시그널 집합..