signal 처리가 잘안돼요.. 도와주세요..

익명 사용자의 이미지

signal 처리가 잘안되요..

제가 한 test 는 메인프로그램에서 1개의 서브 스레드를 생성하고 각자 돌다
가 SIGHUP signal 을 받으면 restart 하는 프로그램입니다. 실행시키면 3개의
스레드가 프로세스로 구동되는데, 제가 그 쓰레드에 kill -HUP 1234(PID 가정)
라고 수행하면 제대로 restart 합니다. 하지만 두번째로 SIGHUP 을 주면
restart가 되지 않습니다. 특히 첫번째 실행후에 최상위 프로세스(아마
initial thread인듯한데...???)는 왜 PID가 바뀌지 않는지도 궁금합니다....
제발 도움좀 주세요..

[실행결과]
[root@/root]# ps -ef | grep th
root 13727 13503 0 1555 pts/0 000000 ./thmain
root 13728 13727 0 1555 pts/0 000000 ./thmain
root 13729 13728 0 1555 pts/0 000000 ./thmain
[root@/root]# kill -HUP 13727
[root@/root]# ps -ef | grep th
root 13727 13503 0 1555 pts/0 000000 ./thmain
root 13732 13727 0 1555 pts/0 000000 ./thmain
root 13733 13732 0 1555 pts/0 000000 ./thmain
[root@/root]# kill -HUP 13727
[root@/root]# ps -ef | grep th
root 13727 13503 0 1555 pts/0 000000 ./thmain
root 13732 13727 0 1555 pts/0 000000 ./thmain
root 13733 13732 0 1555 pts/0 000000 ./thmain

[Makefile]
CC=gcc
LD=gcc
CFLAGS=-g -I../inc -D_REENTRANT
UTILOBJ = thmain.o thdcli1.o
PROGS = thmain
all $(PROGS)
thmain $(UTILOBJ)
$(LD) $(LDFLAGS) -o $@ $(UTILOBJ) -lpthread
clean
-/bin/rm -f *.o $(PROGS)

[thmain.c]
#include
#include
#include
#include

void cli1_thread_cancel();
int cli1_thread();

pthread_t cli1_thd;
pthread_t cli2_thd;
pthread_mutex_t s_lock;
char **gargv;

void xsleep (int no)
{
struct timeval tt;

tt.tv_sec = no / 1000;
tt.tv_usec = no % 1000;

select ( 0, NULL, NULL, NULL, &tt );
}

void aaa_restart(n)
int n;
{
printf("signal = %d\n",n);
printf("thmain restart\n",n);

xsleep(1000);

cli1_thread_cancel();
printf("cli1 thread cancel \n");

execv(gargv[0],gargv);
}

int main(int argc, char **argv)
{
int ret;
signal(SIGHUP,aaa_restart);

pthread_mutex_init(&s_lock,NULL);

gargv = argv;

ret = cli1_thread();
if (ret != 0) return 0;
printf("[ INIT ] cli1 Thread Start...\n");

while (1) {
xsleep(100);
printf("Main Thread Running...\n");
}

}

[thdcli1.c]
#include
#include

extern pthread_t cli1_thd;

void cli1_thread_cancel()
{
if ( pthread_kill ( cli1_thd, 0 ) == 0 )
pthread_kill ( cli1_thd, 31 );
}

void cli_sig31(int sn)
{
pthread_exit(NULL);
}

void* cli1_main()
{
int state;

signal(31,cli_sig31);

xsleep( 1502 );

while (1) {
xsleep(500);
printf("cli1 thread running ...\n");
}
}

int cli1_thread()
{
if (pthread_create(&cli1_thd, NULL, cli1_main, NULL) != 0 ) return -
1;

return 0;
}

익명 사용자의 이미지

exev()계열 함수는 PID가 변화하지 않습니다.
즉, 현재 실행된 상태에서 그 PID를 유지하면서 지정된 프로그램에게
그 PID를 넘겨주게 되며 자신은 종료가 되는겁니다.
SIGHUP은 조금더 봐야할 것 같네요...

익명 사용자의 이미지

signal 핸들러 함수 안에서는 signal 을 처리할수 없습니다..

watchdog 프로세스를 만들고 그를 통해 재시작 시키는 것이

해답인듯 합니다...

익명 사용자의 이미지

참고지만, POSIX thread에서는 thread간에 signal handler는 공유됩니다.
물론, signal과 pthread간의 관계에 있어서 LinuxThread가 완벽하게 표준
을 따르고 있지는 않지만 아무튼 signal handler는 공유됩니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.