thread 생성시 interrupt 에서...

zombie007의 이미지

안녕하세요...
간단한 서버 테스트를 위해.. 클라이언트에서 thread를 1000개 생성하여..
서버에 connect하는 테스트를 하고있는데여....
thread를 한 200여개 생성을 하면..
pthread_create() 함수에서
interrupted system call 에러를 내면서 중단 됩니다..
또 한번은 Broken pipe라는 에레를 내면서 중단 됩니다..

왜이런 현상이 일어나는지여....
밑에 있는 코드는 쓰레드 함수입니다...

고수님들의 조언 부탁드립니다... ^^

void *client_thread(void *cli_info)
{
        int sockfd;
        struct sockaddr_in server;
        char send[100] = {0,};

        if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
        {
                perror(" socket error:");
                exit(-1);
        }

        memset(&server, 0x00, sizeof(server));
        server.sin_family = AF_INET;
        server.sin_port = htons(port);
        server.sin_addr.s_addr = inet_addr(ip);

        if(connect(sockfd, (struct sockaddr *)&server, sizeof(server)) == -1)
        {
                perror(" connect error:");
                exit(-1);
        }

        //sleep(40);
        while(1)
        {
                send[0] = make_rand();
                sleep(5);
                strcpy(send, "Test Packet");
                write(sockfd, send, 100);
        }

        close(sockfd);

        pthread_exit((void *)NULL);
}

int make_rand()
{
        int i;

        srand(time(NULL));
        i = (1+ rand() % 120);
        return i;
}

alsong의 이미지

zombie007 wrote:

Broken pipe라는 에레를 내면서 중단

SIGPIPE 시그널이 받았습니다.
기본적으로 프로세스 종료를 합니다.
시그널 핸들러를 재정의 하세요.

그나저나 백수 언제 탈출하냐... ㅡㅡ; 배고파라.

sjahn90의 이미지

제 생각으로는 thread 생성 실패 때문에 문제가 발생하는거 같습니다. 200개라고 했지만 아마 255정도 생성하다가 실패한거 같습니다.

지금의 현상은 아마 서버에서 accept를 한후 thread를 띄울때 255개를 넘어서 pthread_create가 실패할겁니다. 그러면 클라이언트에서 끊어진 socket에 write하여 broken pipe가 생기는것으로 추정됩니다.

우선 서버나 클라이언트쪽의 Thread 생성 개수 제한에 걸리는지 확인해 보세요.
만약 걸리면 개수를 증가시켜서 테스트해보세요.

댓글 달기

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