signal 처리 중에..

wedwed의 이미지

signal을 처리하는 도중 의문이 생겼는데요....

signalhandler함수로 처리하게 될 경우에요..
시그널이 발생해서 그 handler함수 내에서 처리도중.
그 해당 시그널이 또 발생하게 된다면.

1. 새로운 시그널을 처리하게 되는지...
2. 새로운 시그널을 무시하고 기존 시그널을 계속 처리하는지...
3. 기존 것을 처리하고 또 새로운 시그널을 처리하게 되는지....

handler함수로 인수를 넘겨주지 못해 전역변수 선언해서 사용하는데...
좀 찝찝하네요.....

handler함수 내에서는 전역변수를 변경하지 않는 것이 좋을까요...

질문이 횡성수설하지만 이해하시고... 친절한.. 답변 부탁드립니다...

:oops:

leilei의 이미지

간단히 만들어서 테스트를 해 보시는게 어떨까요?

void signalhandle(int signo)
{
	printf("sigint start \n");
	sleep(10);
	printf("sigint end \n");
	exit(0);
}


void alarmhandler(int signo)
{
	printf("alarm start\n");
	
	sleep(10);
	
	printf("alarm end\n");
}

int main() 
{ 
	signal (SIGALRM, alarmhandler);
	signal (SIGINT, signalhandle);
	
	alarm(5);
	
	while(1)
	{
		sleep(1);
	}
	
	return 0;
} 

또는...

void signalhandle(int signo)
{
	printf("sigint start \n");
	printf("sigint end \n");
}


void alarmhandler(int signo)
{
	printf("alarm start\n");
	
	alarm(2);
		
	sleep(10);
	
	printf("alarm end\n");
}

int main() 
{ 
	signal (SIGALRM, alarmhandler);
	signal (SIGINT, signalhandle);
	
	alarm(5);
	
	while(1)
	{
		sleep(1);
	}
	
	return 0;
} 

대충 이런 식이면 대충 이해가 가지 않을까요?

wedwed의 이미지

어딘가에서 찾았습니다...

시그날 핸들러 함수가 실행되고 있을 때 도착한 다른 시그날이 있다면 무슨 일이 발생할까? 한 특
정한 시그날을 위한 핸들러가 호출되었을 때, 핸들러가 리턴할 때 까지 그 시그날은 보통 블록된다.
만일 같은 종류의 두 개의 시그날이 서로 가까운 시간에 도착한다면, 두 번째것은 첫 번째것이 처리
될때까지 그냥 보유하고 있을 것이다. ( 만일 당신이 이러한 형태의 더 많은 시그날이 도착하도록
허용하기를 원한다면, 핸들러는 sigprocmask를 사용해서 시그날을 명백하게 블록을 해제할 수 있다;
그렇지만, 당신의 핸들러는 다른 종류의 시그날의 배달에 의해서는 여전히 인터럽트되어질 수 있다.
이것을 피하기 위해서, 당신은 sigaction에 인수로써 사용하는 action 구조체의 sa_mask 멤버를 사용
해서 핸들러가 실행되는 동안 블록되어질 시그날을 명백하게 지정할 수 있다. 그들 시그날은 호출
된 핸들러를 위한 시그날에 더해져 있고, 다른 시그날들은 보통 프로세스에 의해서 블록되어진다.
21.7.5절 [Blocking for Handler] 301 페이지 참조.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.