sigprocmask 관련 질문입니다.
다음 소스는 sigprocmask를 이용해서
5초가 알람시그널과 SIGQUIT시그널을 막아놨는데요
그런데도 alarm( 1 );
에 의해 alarm이 정상 처리되면서 1초만에 빠져버리네요.
sigprocmask가 알람을 잘막지 못하는것같은데 원인은 무엇인지요?
#include
#include
#include
void mysig(int signo);
int main()
{
int errno_save , ret;
static struct sigaction act;
sigset_t newmask , oldmask , pendmask;
act.sa_handler = mysig;
sigaction( SIGALRM , &act , NULL );
sigaction( SIGQUIT , &act , NULL );
alarm( 1 );
sigemptyset( &newmask );
sigaddset( &newmask , SIGQUIT );
sigaddset( &newmask , SIGALRM );
if ( sigprocmask( SIG_BLOCK , &newmask , &oldmask ) < 0 )
perror("");
sleep( 5 );
if ( sigpending( &pendmask ) < 0 )
perror("");
if ( sigismember( &pendmask , SIGQUIT ) )
printf("SIGQUIT pending\n" );
if ( sigismember( &pendmask , SIGALRM ) )
printf("SIGALRM pending\n" );
if ( sigprocmask( SIG_SETMASK , &oldmask , NULL ) < 0 )
perror("");
printf("SIGQUIT unblocked\n" );
sleep( 5 );
return 0;
}
void mysig(int signo)
{
fprintf( stderr , "%d signal is received\n" , signo );
}
Re: sigprocmask 관련 질문입니다.
음 저같은 경우엔 잘 동작 합니다.
아마도.. alarm과 sleep을 같이 사용하셔서 그런듯 싶군요
# strace ./sig
execve("./sig", ["./sig"], [/* 32 vars */]) = 0
brk(0) = 0x8049a2c
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x40014000
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=28326, ...}) = 0
old_mmap(NULL, 28326, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40015000
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=4101836, ...}) = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\210\212"..., 4096) = 4096
old_mmap(NULL, 1001532, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x4001c000
mprotect(0x40109000, 30780, PROT_NONE) = 0
old_mmap(0x40109000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0xec000) = 0x40109000
old_mmap(0x4010d000, 14396, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4010d000
close(3) = 0
mprotect(0x4001c000, 970752, PROT_READ|PROT_WRITE) = 0
mprotect(0x4001c000, 970752, PROT_READ|PROT_EXEC) = 0
munmap(0x40015000, 28326) = 0
personality(PER_LINUX) = 0
getpid() = 13442
rt_sigaction(SIGALRM, {0x80487a4, [], 0x4000000}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {0x80487a4, [], 0x4000000}, NULL, 8) = 0
alarm(1) = 0
rt_sigprocmask(SIG_BLOCK, [QUIT ALRM], [], 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [QUIT ALRM], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [QUIT ALRM], NULL, 8) = 0
nanosleep({5, 0}, {5, 0}) = 0
sigpending([ALRM]) = 0
fstat64(0x1, 0xbffff04c) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x40015000
ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
write(1, "SIGALRM pending\n", 16SIGALRM pending
) = 16
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGALRM (자명종 시계) ---
write(2, "14 signal is received\n", 2214 signal is received
) = 22
sigreturn() = ? (mask now [])
write(1, "SIGQUIT unblocked\n", 18SIGQUIT unblocked
) = 18
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({5, 0}, {5, 0}) = 0
munmap(0x40015000, 4096) = 0
_exit(0) = ?
#
댓글 달기