When I create a thread ( pthread_create()
) from my main process, I see three (3) threads in the ps
list, why is this? That is, I see a process for the main thread, one for the created thread and the third for something else. Something else? Everything works fine, I'm just wondering what an additional process is.
~/ cat test.c #include <errno.h> #include <pthread.h> static pthread_t thread; void * test_thread(void * ptr) { sleep(30); return(ptr); } void thread_init(void) { if (pthread_create( &thread , NULL, test_thread, NULL)) perror("Thread not created!"); } int main(int argc, char ** argv) { thread_init(); sleep(30); }
When I execute this code on a system running Linux 2.6.14 and BusyBox (but using bash 2.04g), the ps
list that I get after rebooting and running my test program above:
... 52 root SW [kswapd0] 667 root SW [mtdblockd] 710 root SWN [jffs2_gcd_mtd4] 759 root 980 S /bin/sh 760 root 500 S /bin/inetd 761 root 516 S /bin/boa 762 root 644 S /sbin/syslogd -n 763 root 640 S /sbin/klogd -n 766 root 1516 S /bin/sshd -i 767 root 1036 S -sh 768 root 420 S ./test 769 root 420 S ./test 770 root 420 S ./test 771 root 652 R ps
The kernel is the 2.6.14 kernel with several driver modules added.
Jamie source share