Hi All, I Have the following small code for creating threads.
#include <stdio.h> #include <pthread.h>
void my_func_1 (void *arg) { while(1) {} }
int main() { pthread_t thread_1; pthread_create(&thread_1, NULL,(void*)& my_func_1, NULL);
while(1) { } exit(0); }
gcc -lpthread -o thread test.c
I expect to have created 2 threads. But when I do ps -ef | grep thread I see 3.
Say If i use pthread_create and create one more thread, then instead of 3 I see
4. Does any one know what is the reason for this behavior?
Hi
The linux kernel does not support the concept of threads (there are no thread system calls). the only system calls for achieving this somultaneous mechanism would be fork() and exec(). The pthreads library used these system calls.
the two threads that are created are your main() thread and myfunc_1() thread. the third thread is the internal controll thread which takes care of the parallel mechanism in the user space . we can look at that process as a virtual machine implementing threads for linux.
regards nix.
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/