좀비 프로세스 살려내기

ymkim00의 이미지

매우 열악한 임베디드 환경에서 프로그래밍을 하고 있습니다.

CPU : MPC860
MAIN MEMORY : 16MB

이 16메가안에서 커널 및 램 디스크가 올라가기때문에 실제 사용가능한 메모리가 아주 작습니다.
때문에 응용프로그램이 돌다가 FTP 데몬에서 2,3메가 바이트의 데이터만 올라와도 응용프로그램의 쓰레드가 좀비로 변해버립니다.
응용프로그램에는 9개의 쓰레드가 돌고 있습니다.


void *aaa_thread(void *arg)
{
    for(;;)
    {
	
		
    }
    pthread_exit(NULL);
}

int main(int argc, char **argv)
{
    FILE *fp;
    int i, n, temp;
    unsigned int card_data;
    unsigned char read_data[10], stat, ch;
    unsigned long m;
    

	
	res = pthread_create(&AAA_thread, NULL, AAA_thread, NULL);
	if(res != 0)
	{
	    printf("Thread creation failed");
	    exit(EXIT_FAILURE);
	}


	
	while(1);
	
	close(dev);


	res = pthread_join(AAA_thread, &aaa_result);
	if(res != 0)
	{
	    printf("Thread join failed");
	    exit(EXIT_FAILURE);
	}

    return 0;
}

메인소스를 간단하게 정리해봤습니다.
보시는것과 같이 메인함수내에서 하는일은 9개의 스레드를
오픈시키는역할을 뺴곤 아무것도 수행을 하지않습니다.
무한루프를 돌리는 while(1)안에 좀비를 찾아내서
종료시킨 후 다시 돌리는 루틴을 넣고싶은데..

리눅스 프로그램은 첨이라 쉽지가 않습니다.

고수님들의 도움이 필요합니다.
적은메모리에서 아주 많은 일을 하다보니 이러한 문제가 발생을
하고있습니다.

litdream의 이미지

저도 초보이기때문에, 잘은 모르지만 제 의견은,
코드 자체에서 봤을때, 데드락 일지도 모르겠단 생각이 드네요.
( 좀비프로세스와 데드락은 원인이 다른경우가 더 많죠. )

데드락이 맞다면, 이건 메모리의 양과는 관계가 없습니다.
만약에 p_thread 가 세마포어같은걸 사용한다면
lock 을 잘 살펴보시면 데드락을 푸실수 있을겁니다.
그런 로직이 while 루프안에만 들어가는게 아니라,
쓰레드에서도 lock 을 release 하는 시점을 잘 다뤄주는게
제 가정이 옳을때의 해법이 아닌가 생각합니다.

삽질의 대마왕...

댓글 달기

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