Threads are created as seperate processes
Hi,
I have a small prog which creates threads, but on Redhat AS 2.1 kernel : 2.4.9-e.24 =============================================================== pid_t pid=fork(); if (pid == 0) { //create another child pid_t newchild = fork(); if (newchild == 0) { //child of child /* Create independant threads each of which will execute function */ iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); /* Wait till threads are complete before main continues. Unless we */ /* wait we run the risk of executing an exit which will terminate */ /* the process and all threads before the threads have completed. */ sleep(50); pthread_join( thread1, NULL); pthread_join( thread2, NULL); } else { p1= pthread_create( &thread1, NULL, print_message_function, (void*) message1); p2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); sleep (50); //just to check pthread_join( thread1, NULL); pthread_join( thread2, NULL); } } else{ waitpid(pid,NULL,0); } return 0; } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } ================================================================ this progs actually creates 2 processes and 4 threads, but when i check the with ps -e i see many process instead of threads, here is the sample output of pstree pstree -p 22203 threads(22203)---threads(22204)-+-threads(22205)---threads(22207) `-threads(22206) My questions is i should see only 2 processes but here i am seeing many processes, the threads are not getting created as threads but as processes... is this is a known problem , if so is there any fix avaliable... Thanks in advance. |
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
|
This thread might help answer your question:
http://www.linuxquestions.org/questi...37#post2014737 |
Thanks for the reply. it answered my question about processes and threads.
But i still have one question in Fedora (Kernel 2.6) we have something known as NPTL is it Native Pthread Libaray and on such kernel will the threads will be threads and not processess(LWP). |
All times are GMT -5. The time now is 03:46 PM. |