쓰레드를 생성하려고 하는데....

익명 사용자의 이미지

redhat 7.1에서 하나의 프로세스에서 쓰레드를 생성하려고 하는데요...
물론 아래의 코드가 돌아가지 않는것은 아니지만...
히안하게도 ps를 쳐서 프로세스를 보면 3개의 프로세스가 생겨 있읍니
다...
이런 해괴한 경우를 당하신적이 있습니까??

무어가 잘못된건지 아시면 제발줌 알려주세요... plz....

// gcc -pthread -o thread thread.c
#include
#include

void* Run(void* pParam);

int main()
{
pthread_t tt;
void * pResult;

if (pthread_create(&tt, NULL, Run, (void*)0) != 0)
return -1;

pthread_join(tt, &pResult);
printf("kekeke\n");

return 0;
}

void* Run(void* pParam)
{
printf("kekeke(%d)\n", getpid());
sleep(10);
}

익명 사용자의 이미지

예리한 관찰력이시네요;;
저도 님과 같은 호기심으로 이것 저것 찾아 보았는데
답은 얻은 글은 바로 아래와 같습니다.

D.5 When I'm running a program that creates N threads, top or ps display N+2
processes that are running my program. What do all these processes correspond to?

Due to the general "one process per thread" model, there's one process for the
initial thread and N processes for the threads it created using
pthread_create. That leaves one process unaccounted for. That extra process
corresponds to the "thread manager" thread, a thread created internally by
LinuxThreads to handle thread creation and thread
termination. This extra thread is asleep most of the time.

예를 들어 보면,

제가 만든 프로그램의 ps -ef f 의 예입니다.,
요런식으로 ps 명령을 내리면 트리모양으로 이쁘게 상속관계를 보여주는 데,
음 윗글 처럼 관리자 쓰레드가 존재 하기 때문이죠..

3143이 메인프로세스 3144가 쓰레드 메니져
3145~ 이넘들이 만들어진 쓰레드가 되겠죠;

zeroin 3143 25003 0 0001 ? S 000 \_ zsvr
zeroin 3144 3143 0 0001 ? S 000 \_ zsvr
zeroin 3145 3144 0 0001 ? S 000 \_ zsvr
zeroin 3146 3144 0 0001 ? S 000 \_ zsvr
zeroin 3147 3144 0 0001 ? S 000 \_ zsvr
zeroin 3148 3144 0 0001 ? S 000 \_ zsvr
zeroin 3149 3144 0 0001 ? S 000 \_ zsvr
zeroin 3150 3144 0 0001 ? S 000 \_ zsvr
zeroin 3151 3144 0 0001 ? S 000 \_ zsvr
zeroin 3152 3144 0 0001 ? S 000 \_ zsvr
zeroin 3153 3144 0 0001 ? S 000 \_ zsvr
zeroin 3154 3144 0 0001 ? S 000 \_ zsvr
zeroin 3155 3144 0 0001 ? S 000 \_ zsvr
zeroin 3156 3144 0 0001 ? S 000 \_ zsvr
zeroin 3157 3144 0 0001 ? S 000 \_ zsvr
zeroin 3158 3144 0 0001 ? S 000 \_ zsvr
zeroin 3159 3144 0 0001 ? S 000 \_ zsvr
zeroin 3160 3144 0 0001 ? S 000 \_ zsvr

윗글은 http//pauillac.inria.fr/~xleroy/linuxthreads/faq.html
이고

쓰레드에 관한 좀더 자세한 정보 모음은 일전에 제가 정리한 글이 있는데,
http//www.ezdoum.com/stories.php?story=02/05/09/5651994
를 참조 하세요.

익명 사용자의 이미지

고맙습니다....
꾸뻑... ^^

댓글 달기

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