Why do I see one more thread than the number I created in my `ps` listing?

后端 未结 3 845
我在风中等你
我在风中等你 2021-01-19 05:27

When I create a thread (pthread_create()) from my main process, I see three (3) threads in the ps listing, why is this? That is, I see the process

3条回答
  •  旧巷少年郎
    2021-01-19 05:46

    You are seeing one thread more than you are creating because you are not counting the programs main thread.

    Every time you start a program, you fire up a process that has 1 thread running. If you pthread_create one thread, then you have two threads running. You pthread_create a second one and you get three threads running.

    That is why your ps (which according to you on one of the comments) shows threads, is showing you one more than the number of your pthread_creates.

提交回复
热议问题