raise() — 송신 신호

형식

#include <signal.h>
int raise(int sig);

언어 레벨

ANSI

스레드세이프

설명

raise() 함수는 신호 sig를 실행 중인 프로그램에 보냅니다. 컴파일 명령에서 SYSIFCOPT(*ASYNCSIGNAL)로 컴파일하는 경우, 이 기능은 비동기 신호를 사용합니다. 이 함수에 대한 비동기 버전은 프로세스 또는 스레드에 신호를 예외 처리합니다.

리턴값

성공하는 경우 raise() 함수는 0을 리턴하며 실패한 경우 영(0)이 아닌 값을 리턴합니다.

이 예는 신호 SIGUSR1에 대해 sig_hand라는 신호 핸들러를 설정합니다. SIGUSR1 신호가 발생하고 신호의 처음 9번 발생을 무시할 때마다 신호 핸들러가 호출됩니다. 10번째로 발생한 신호에서 10의 오류 코드를 가진 프로그램을 종료합니다. 호출될 때마다 신호 핸들러가 재설정될 것이라는 점을 참고하십시오.
#include <signal.h>
#include <stdio.h>
 
void sig_hand(int);  /* declaration of sig_hand() as a function */
 
int main(void)
{
   signal(SIGUSR1, sig_hand); /* set up handler for SIGUSR1 */
 
   raise(SIGUSR1);   /* signal SIGUSR1 is raised */
                     /* sig_hand() is called     */
}
 
void sig_hand(int sig)
{
   static int count = 0;  /* initialized only once */
 
   count++;
   if (count == 10)  /* ignore the first 9 occurrences of this signal */
      exit(10);
   else
      signal(SIGUSR1, sig_hand);  /* set up the handler again */
}
/* This is a program fragment and not a complete program */

관련 정보