SIGACTION

Section: Linux Programmer's Manual (2)
Updated: 8 May 1999
Index
Return to Main Contents
 

À̸§

sigaction, sigprocmask, sigpending, sigsuspend - POSIX ½Ã±×³Î ó¸® ÇÔ¼ö  

»ç¿ë¹ý

#include <signal.h>

int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);

int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);

int sigpending(sigset_t *set);

int sigsuspend(const sigset_t *mask);  

¼³¸í

sigaction ½Ã½ºÅÛ È£ÃâÀº ƯÁ¤ ½Ã±×³ÎÀÌ ¼ö½ÅµÇ¾úÀ» ¶§, ÇÁ·Î¼¼½º°¡ ÃëÇÒ ¾×¼ÇÀ» º¯°æÇϴµ¥ »ç¿ëµÈ´Ù.

signum ´Â ½Ã±×³ÎÀ» °¡¸®Å°¸ç, SIGKILL °ú SIGSTOP ¸¦ Á¦¿ÜÇÑ ¸ðµç ½Ã±×³Î °ªÀÌ µÉ ¼ö ÀÖ´Ù.

act °¡ nullÀÌ ¾Æ´Ò ¶§, ½Ã±×³Î signum ¿¡ ´ëÇÑ »õ·Î¿î ¾×¼ÇÀº act °¡ µÇ¸ç, oldact ÀÌ nullÀÌ ¾Æ´Ò ¶§, ±âÁ¸ÀÇ ¾×¼ÇÀº oldact ¿¡ ÀúÀåµÈ´Ù.

sigaction ±¸Á¶´Â ´ÙÀ½°ú °°ÀÌ Á¤ÀǵȴÙ.

struct sigaction {
    void (*sa_handler)(int);
    void (*sa_sigaction)(int, siginfo_t *, void *);
    sigset_t sa_mask;
    int sa_flags;
    void (*sa_restorer)(void);
}

¾ÆÅ°ÅØÃÄ¿¡ µû¶ó °ø¿ëü·Î µÇ¾î Àֱ⵵ ÇϹǷÎ, sa_handler ¿Í sa_sigaction À» ¸ðµÎ ÁöÁ¤ÇÏÁö ¸»¶ó.

sa_restorer ¿ä¼Ò´Â ¾²ÀÌÁö ¾ÊÀ¸¸ç, »ç¿ëµÇ¾î¼­´Â ¾ÈµÈ´Ù. POSIX´Â sa_restorer ¿ä¼Ò¸¦ °®Áö ¾Ê´Â´Ù.

sa_handler ´Â signum ½Ã±×³ÎÀÌ ¿À¸é ½ÇÇàµÇ´Â ¾×¼ÇÀ» ¸í½ÃÇϸç, µðÆúÆ® ¾×¼ÇÀ» ÃëÇ϶ó´Â SIG_DFL , ½Ã±×³ÎÀ» ¹«½ÃÇ϶ó´Â SIG_IGN , ½Ã±×³ÎÀ» ó¸®Çϴ ƯÁ¤ ÇÔ¼ö¿¡ ´ëÇÑ Æ÷ÀÎÅÍ ÁßÀÇ Çϳª°¡ µÉ ¼ö ÀÖ´Ù. ¼¼¹ø°ÀÇ °æ¿ì ½Ã±×³Î ó¸® ÇÔ¼ö´Â ½Ã±×³Î ¹øÈ£¸¸À» À¯ÀÏÇÑ Àμö·Î °®´Â´Ù.

sa_sigaction ¶ÇÇÑ signum ½Ã±×³Î°ú ¿¬°áµÈ ¾×¼ÇÀ» ¸í½ÃÇÑ´Ù. ó¸® ÇÔ¼ö´Â ½Ã±×³Î ¹øÈ£¸¦ ù¹ø° Àμö·Î, siginfo_t ¿¡ ´ëÇÑ Æ÷ÀÎÅ͸¦ µÎ¹ø° Àμö·Î, ±×¸®°í voidÇü Æ÷ÀÎÅͷΠij½ºÆ®µÈ ucontext_t ¿¡ ´ëÇÑ Æ÷ÀÎÅ͸¦ ¼¼¹ø° Àμö·Î °®´Â´Ù.

sa_mask ´Â ½Ã±×³Î Çڵ鷯ÀÇ ½ÇÇà µ¿¾È ºí·ÏÈ­µÇ¾î¾ß ÇÏ´Â ½Ã±×³ÎÀÇ ¸¶½ºÅ©¸¦ Á¦°øÇÑ´Ù. ¶ÇÇÑ, SA_NODEFER ¶Ç´Â SA_NOMASK ÀÌ »ç¿ëµÇÁö ¾ÊÀ¸¸é, Çڵ鷯¸¦ ½Ãµ¿½ÃÄ×´ø ±× ½Ã±×³Îµµ ºí·ÏÈ­µÈ´Ù.

sa_flags ´Â ½Ã±×³Î ó¸® ÇÁ·Î¼¼½ºÀÇ ÇàÀ§¸¦ º¯°æ½ÃÅ°´Â ÀÏ·ÃÀÇ Ç÷¡±×µéÀ» ¸í½ÃÇÑ´Ù. ÀÌ´Â bitwise ȤÀº Ç÷¡±×´Â ¾Æ·¡ Ç÷¡±× µéÀÇ 0°³ ÀÌ»óÀÇ OR ºñÆ® ¿¬»êÀ¸·Î ¸¸µé¾îÁø´Ù.

SA_NOCLDSTOP
signum °¡ SIGCHLD À̸é ÀÚ½Ä ÇÁ·Î¼¼½º°¡ ÁßÁöµÇ¾îµµ ÅëÁö¸¦ ¹ÞÁö ¾Ê´Â´Ù. (Áï, ÀÚ½Ä ÇÁ·Î¼¼½ºµéÀÌ SIGSTOP, SIGTSTP, SIGTTIN , SIGTTOU Áß Çϳª¸¦ ¼ö½ÅÇÒ ¶§)
SA_ONESHOT ¶Ç´Â SA_RESETHAND
½Ã±×³Î 󸮱Ⱑ È£ÃâµÇ¾î Çѹø ½ÇÇàµÈ ÈÄ, ½Ã±×³Î ¾×¼ÇÀ» ¿ø·¡ÀÇ µðÆúÆ® ¾×¼ÇÀ¸·Î µÇµ¹·Á ³õ´Â´Ù. (ÀÌ´Â signal(2) È£Ãâ¿¡ ´ëÇÑ ±âº» ÇàÀ§ÀÌ´Ù.)
SA_RESTART
ÀϺΠ½Ã½ºÅÛ È£ÃâµéÀÌ ½Ã±×³ÎÀ» ÅëÇØ Àç½ÃÀÛÇÒ ¼ö ÀÖµµ·Ï ÇÔÀ¸·Î¼­ BSD ½Ã±×³Î°úÀÇ È£È¯¼ºÀ» Á¦°øÇÑ´Ù.
SA_NOMASK or SA_NODEFER
¾î¶² ½Ã±×³Î 󸮱âÀÇ µ¿ÀÛµ¿¾È ±× ½Ã±×³Î ÀÚ½ÅÀ» ¸·Áö ¾Ê´Â´Ù.
SA_SIGINFO
½Ã±×³Î 󸮱Ⱑ ÇÑ °³°¡ ¾Æ´Ñ 3°³ÀÇ Àμö¸¦ ÃëÇÑ´Ù. ÀÌ °æ¿ì, sa_handler ´ë½Å¿¡ sa_sigaction ÀÌ ¼³Á¤µÇ¾î¾ß ÇÑ´Ù. (sa_sigaction Çʵå´Â ¸®´ª½º 2.1.86¿¡¼­ Ãß°¡µÇ¾ú´Ù.)

sa_sigaction ÀÇ siginfo_t º¯¼ö´Â ´ÙÀ½ÀÇ ¿ä¼ÒµéÀ» °®´Â ±¸Á¶Ã¼(struct)ÀÌ´Ù.


siginfo_t {
    int      si_signo;  /* ½Ã±×³Î ³Ñ¹ö */
    int      si_errno;  /* errno °ª */
    int      si_code;   /* ½Ã±×³Î ÄÚµå */
    pid_t    si_pid;    /* ÇÁ·Î¼¼½º ID º¸³»±â */
    uid_t    si_uid;    /* ÇÁ·Î¼¼½º¸¦ Àü¼ÛÇÏ´Â ½ÇÁ¦ »ç¿ëÀÚ ID */
    int      si_status; /* Exit °ª ¶Ç´Â ½Ã±×³Î */
    clock_t  si_utime;  /* ¼Ò¸ðµÈ »ç¿ëÀÚ ½Ã°£ */
    clock_t  si_stime;  /* ¼Ò¸ðµÈ ½Ã½ºÅÛ ½Ã°£ */
    sigval_t si_value;  /* ½Ã±×³Î °ª */
    int      si_int;    /* POSIX.1b ½Ã±×³Î */
    void *   si_ptr;    /* POSIX.1b ½Ã±×³Î */
    void *   si_addr;   /* ½ÇÆи¦ ÃÊ·¡ÇÑ ¸Þ¸ð¸® À§Ä¡ */
    int      si_band;   /* ¹êµå À̺¥Æ® */
    int      si_fd;     /* ÆÄÀÏ ±â¼úÀÚ */
}

si_signo, si_errno ±×¸®°í si_code ´Â ¸ðµç ½Ã±×³Î¿¡ ´ëÇØ Á¤ÀǵǾú´Ù. kill(2), POSIX.1b ½Ã±×³Î°ú SIGCHLDÀº si_pid °ú si_uid À» ä¿î´Ù. SIGCHLD Àº ¶ÇÇÑ si_status, si_utime, si_stime À» ä¿î´Ù. si_int ±×¸®°í si_ptr ´Â POSIX.1b ½Ã±×³ÎÀÇ ¼Û½ÅÀÚ¿¡ ÀÇÇØ ¸í½ÃµÈ´Ù. Á»´õ ÀÚ¼¼ÇÑ »çÇ×À» º¸·Á¸é, sigqueue(2) À» ÂüÁ¶Ç϶ó. SIGILL, SIGFPE, SIGSEGV ±×¸®°í SIGBUSÀº si_addr ¸¦ ¿À·ùÀÇ ÁּҷΠä¿î´Ù. SIGPOLL Àº si_band¿Ísi_fd ¸¦ ä¿î´Ù. si_code ´Â ¿Ö ½Ã±×³ÎÀÌ º¸³»Á³´ÂÁö¿¡ ´ëÇØ Áö½ÃÇÑ´Ù. ÀÌ´Â bitmask°¡ ¾Æ´Ñ °ªÀÌ´Ù. ³ª¿Ã ¼ö ÀÖ´Â ¸ðµç ½Ã±×³Î °ªÀº ÀÌ Å×ÀÌºí¿¡ ³ª¿­µÇ¾î ÀÖ´Ù.
si_code
ValueSignal origin
SI_USERkill, sigsend or raise
SI_KERNELThe kernel
SI_QUEUEsigqueue
SI_TIMERtimer expired
SI_MESGQmesq state changed
SI_ASYNCIOAIO completed
SI_SIGIOqueued SIGIO
SIGILL
ILL_ILLOPCillegal opcode
ILL_ILLOPNillegal operand
ILL_ILLADRillegal addressing mode
ILL_ILLTRPillegal trap
ILL_PRVOPCprivileged opcode
ILL_PRVREGprivileged register
ILL_COPROCcoprocessor error
ILL_BADSTKinternal stack error
SIGFPE
FPE_INTDIVinteger divide by zero
FPE_INTOVFinteger overflow
FPE_FLTDIVfloating point divide by zero
FPE_FLTOVFfloating point overflow
FPE_FLTUNDfloating point underflow
FPE_FLTRESfloating point inexact result
FPE_FLTINVfloating point invalid operation
FPE_FLTSUBsubscript out of range
SIGSEGV
SEGV_MAPERRaddress not mapped to object
SEGV_ACCERRinvalid permissions for mapped object
SIGBUS
BUS_ADRALNinvalid address alignment
BUS_ADRERRnon-existant physical address
BUS_OBJERRobject specific hardware error
SIGTRAP
TRAP_BRKPTprocess breakpoint
TRAP_TRACEprocess trace trap
SIGCHLD
CLD_EXITEDchild has exited
CLD_KILLEDchild was killed
CLD_DUMPEDchild terminated abnormally
CLD_TRAPPEDtraced child has trapped
CLD_STOPPEDchild has stopped
CLD_CONTINUEDstopped child has continued
SIGPOLL
POLL_INdata input available
POLL_OUToutput buffers available
POLL_MSGinput message available
POLL_ERRi/o error
POLL_PRIhigh priority input available
POLL_HUPdevice disconnected

sigprocmask È£ÃâÀº ÇöÀç ºí·ÏÈ­µÈ ½Ã±×³ÎµéÀ» º¯°æ½ÃÅ°´Âµ¥ »ç¿ëµÈ´Ù. È£ÃâÀº ÁöÁ¤µÈ how °ª¿¡ µû¶ó ´Ù¸£°Ô µ¿ÀÛÇÑ´Ù.

SIG_BLOCK
set Àμö°¡ ÁöÁ¤ÇÑ ½Ã±×³Î ÁýÇÕÀÌ ºí·Ï½Ãų ½Ã±×³Î ÁýÇÕ¿¡ ´õÇØÁø´Ù.
SIG_UNBLOCK
set ¿¡ Æ÷ÇÔµÈ ½Ã±×³ÎµéÀÌ ºí·Ï½Ãų ½Ã±×³ÎµéÀÇ ÁýÇÕ¿¡¼­ »èÁ¦µÈ´Ù. ºí·ÏÇÏ°í ÀÖÁö ¾ÊÀº ½Ã±×³ÎÀ» »èÁ¦ÇÏ·Á Çصµ ±¦Âú´Ù.
SIG_SETMASK
ºí·ÏÈ­ÇÒ ½Ã±×³Î ÁýÇÕÀ» set À¸·Î ¼³Á¤ÇÑ´Ù.

oldset ÀÌ nullÀÌ ¾Æ´Ò ¶§, ±âÁ¸ÀÇ ¸¶½ºÅ© ½Ã±×³Î ÁýÇÕÀº oldset ¿¡ ÀúÀåµÈ´Ù.

sigpending È£ÃâÀº ºí·ÏÈ­¿¡ ¸·Çô ±â´Ù¸®°í ÀÖ´Â ½Ã±×³ÎÀ» »ìÆ캼 ¼ö ÀÖµµ·Ï ÇØÁØ´Ù. ±â´Ù¸®´Â ½Ã±×³ÎµéÀÇ ½Ã±×³Î ¸¶½ºÅ©´Â set ³»¿¡ ÀúÀåµÈ´Ù.

sigsuspend È£ÃâÀº ÇÁ·Î¼¼½º°¡ ¸·°í ÀÖ´Â ½Ã±×³Î ¸¶½ºÅ©¸¦ ÁöÁ¤ÇÑ mask ·Î Àá½Ã ´ëüÇÏ°í, ´ÙÀ½ ½Ã±×³ÎÀÌ ¼ö½ÅµÉ ¶§±îÁö ÇÁ·Î¼¼½º¸¦ ÁßÁö½ÃŲ´Ù.  

¹Ýȯ°ª

sigaction , sigprocmask , sigpending ´Â ¼º°øÇϸé 0À» ½ÇÆÐÇϸé -1À» ¸®ÅÏÇÑ´Ù. sigsuspend Ç×»ó -1À» ¸®ÅÏÇÑ´Ù. º¸Åë ¿¡·¯ EINTR °ú ÇÔ²².

 

¿¡·¯

EINVAL
ÁöÁ¤ÇÑ ½Ã±×³ÎÀÌ ºÎÀûÀýÇÏ´Ù. ȤÀº ¹ÞÀ» ¼ö ¾ø´Â SIGKILL ¶Ç´Â SIGSTOP ¿¡ ´ëÇÑ ¾×¼ÇÀ» º¯°æÇÏ·Á°í Çß´Ù.
EFAULT
act, oldact, set ¶Ç´Â oldset ÀÌ ÇÁ·Î¼¼½ºÀÇ ¸Þ¸ð¸® ¿µ¿ªÀÌ ¾Æ´Ñ °÷À» °¡¸®Å°°í ÀÖ´Ù.
EINTR
½Ã½ºÅÛ È£ÃâÀÌ ÀÎÅÍ·´Æ®µÇ¾ú´Ù.
 

ÁÖÀÇ

sigprocmask È£Ãâ·Î SIGKILL ¶Ç´Â SIGSTOP À» ºí·ÏÈ­ÇÒ ¼ö ¾ø´Ù. ÀÌ·± ¸í·ÉÀº ¹«½ÃµÈ´Ù.

POSIX¿¡ µû¸£¸é, ÇÁ·Î¼¼½º°¡ kill() ¶Ç´Â raise() ÇÔ¼ö°¡ ¸¸µé¾î ³½ °ÍÀÌ ¾Æ´Ñ GFPE, SIGILL, ȤÀº SIGSEGV¸¦ ¹«½ÃÇÑ ÀÌÈÄÀÇ ÇÁ·Î¼¼½ºÀÇ µ¿ÀÛÀº Á¤ÀǵÇÁö ¾Ê´Â´Ù. Á¤¼ö¸¦ 0À¸·Î ³ª´« °á°ú ¶ÇÇÑ Á¤ÀǵÇÁö ¾Ê´Â´Ù. ÀϺΠ¾ÆÅ°ÅØÃÄ¿¡¼± 0À¸·Î ³ª´©±â°¡ SIGFPE ½Ã±×³ÎÀ» ¸¸µé¾î ³¾ °ÍÀÌ´Ù. (¶ÇÇÑ °¡Àå Å« À½ÀÇ Á¤¼ö¸¦ -1·Î ³ª´©¾îµµ SIGFPE¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Ù.) ÀÌ ½Ã±×³ÎÀ» ¹«½ÃÇÏ¸é ¹«ÇÑ ·çÇÁ¸¦ ÃÊ·¡ÇÒ ¼ö ÀÖ´Ù.

POSIX ½ºÆåÀº ¿ÀÁ÷ SA_NOCLDSTOP ¸¸À» Á¤ÀÇÇÑ´Ù . ´Ù¸¥ sa_flags ÀÇ »ç¿ëÀº À̽ÄÀÌ ºÒ°¡´ÉÇÏ´Ù.

SA_RESETHAND Ç÷¡±×´Â µ¿ÀÏÇÑ À̸§ÀÇ SVr4 Ç÷¡±×¿Í ȣȯ°¡´ÉÇÏ´Ù.

SA_NODEFER Ç÷¡±×´Â Ä¿³Î 1.3.9°ú »õ·Î¿î ¹öÀüÇÏ¿¡¼­ µ¿ÀÏÇÑ À̸§ÀÇ SVr4 Ç÷¡±×¿Í ȣȯ°¡´ÉÇÏ´Ù.

SVr4 ȣȯ¼ºÀ» À§ÇÑ SA_RESETHAND ¿Í SA_NODEFER À̸§µéÀº ¿ÀÁ÷ ¶óÀ̺귯¸® ¹öÀü 3.0.9 ±×¸®°í ±× ÀÌÈÄÀÇ ¹öÀü¿¡¼­¸¸ Á¸ÀçÇÑ´Ù.

SA_SIGINFO Ç÷¡±×´Â POSIX.1b¿¡ ÀÇÇؼ­¸¸ ¸í½ÃµÈ´Ù. ÀÌ¿¡ ´ëÇÑ Áö¿øÀº ¸®´ª½º 2.2¿¡ Ãß°¡µÇ¾ú´Ù.

sigaction ÇöÀç ½Ã±×³Î Ã³¸®±â¿¡ Äõ¸®¸¦ Çϱâ À§ÇØ ³Î µÎ¹ø° Àμö·Î È£ÃâµÉ ¼ö ÀÖ´Ù. À̸¦ ³Î µÎ¹ø° ±×¸®°í ¼¼¹ø° Àμöµé·Î À̸¦ È£ÃâÇÔÀ¸·Î¼­ ÇöÀç ¸Ó½Å¿¡ ´ëÇÑ ÁÖ¾îÁø ½Ã±×³ÎÀÌ Å¸´çÇÑ°¡¸¦ üũÇϴµ¥ »ç¿ëµÉ ¼ö ÀÖ´Ù.

½Ã±×³Î ü°è Á¶ÀÛ¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ Á¤º¸¸¦ ¾òÀ¸·Á¸é, sigsetops(3) À» ÂüÁ¶Ç϶ó.  

ȣȯ

POSIX, SVr4. SVr4 ´Â EINTR Á¶°Ç¿¡ ´ëÇÑ ¹®¼­¸¦ Á¦°øÇÏÁö ¾Ê´Â´Ù.  

°ü·Ã Ç׸ñ

kill(1), kill(2), killpg(2), pause(2), raise(3), siginterrupt(3), signal(2), signal(7), sigsetops(3), sigvec(2)  

¹ø¿ª

ASPLINUX <man@asp-linux.co.kr> 2000³â 7¿ù 29ÀÏ
ÇÑ±Û Manpage ÇÁ·ÎÁ§Æ® (http://man.kldp.org) 2005³â 2¿ù 13ÀÏ


 

Index

À̸§
»ç¿ë¹ý
¼³¸í
¹Ýȯ°ª
¿¡·¯
ÁÖÀÇ
ȣȯ
°ü·Ã Ç׸ñ
¹ø¿ª

This document was created by man2html, using the manual pages.
Time: 06:48:01 GMT, February 13, 2005