Why do I see another stream than the number that I created in my BusyBox `ps` list?

Possible duplicate:
Why am I seeing another stream than the number I created in my ps list?

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 

Here they are: three consecutive numbered PID processes. It doesn't seem to do any harm, but I'm curious.

+4
source share
1 answer

Could it be that ps displays 1 line for the process and 2 lines for both threads. You do not show how ps is issued, which version, and you do not include the entire ps command.

ps usually only shows processes, not threads.

0
source

Source: https://habr.com/ru/post/1384963/


All Articles