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
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_create
s.
Could it be that ps is displaying 1 line for the process and 2 lines for both threads. You don't show how ps is being issued, what version, nor do you contain the entire about of the ps command.
ps typically shows only processes, not threads.
According to busybox.net/downloads/BusyBox.html the ps command will not show threads. ps -T will show threads. So if you are sure only ps is being issued (I don't know about alias in BusyBox or anything at all, I've never used it) then you are seeing 3 processes, not threads.
Also you may be using an old version of BusyBox? Refer to this bug report: bugs.busybox.net/show_bug.cgi?id=3835
It is likely the "thread manager" thread. See answer D.5 at this link.
You won't see the extra process listed on most modern Linux systems if they are using NPTL. But I searched and it sounds like BusyBox uses ulibc which I think only added NPTL support recently. So I don't know for sure, but my guess is you are using LinuxThreads and seeing the manager thread as the extra thread.