시그널 : 예기치 않은 상황이 발생할 때 이를 알리는 소프트웨어 인터럽트
/usr/include/asm/siganl.h. 에서 확인가능
* alarm()
unsigned int alarm(unsigned int sec)
- sec 은 초 단위를 의미
- 한 프로세스 당 오직 하나의 알람 설정 가능
- alarm(0) : 이전에 설정된 알람은 취소된다
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
int count =0; // 카운트 변수 초기화
alarm(5); // 알람 시그널 - 5초후 작동
printf("알람 시크널 테스트입니다\n");
while(1) { // 무한루프
sleep(1); // 1초 sleep
printf("%d 초 경과\n",count);
count++; // 카운트값 1씩 증가
}
printf("alarm signal fail"); // 시그널 실패 시
}
'Linux' 카테고리의 다른 글
#3 Linux ( 프로그램 실행 ) (0) | 2022.11.22 |
---|---|
#2 Linux ( 프로세스 ) (0) | 2022.11.22 |
#1 Linux (0) | 2022.11.02 |