-1

How can I see the number of threads placed in a process in C ?

Actually, What I find out is whether newly-created process has one thread or no thread.(I am working in Linux)

John
  • 6,433
  • 7
  • 47
  • 82
Goktug
  • 855
  • 1
  • 8
  • 21
  • 4
    Every process has at least one thread (the "main" thread) – John Mar 04 '18 at 09:17
  • In this case, we can say that when we create a thread in a process by using pthread_create() method, two threads exist in that process ? – Goktug Mar 04 '18 at 09:21
  • 1
    at least two threads – Tony Mar 04 '18 at 09:33
  • @Goktug In C threading isn't very evolved. I believe the call you are looking for is `pthread_join()` which will block waiting for the thread to terminate. Any other status updates requires you to roll your own shared data structure. Yes, in theory `pthread_create()` will add a thread (although I've seen it butchered and abused many times). – John Mar 04 '18 at 10:09

1 Answers1

1

The pthread_create() function starts a new thread in the calling process.So technically yes you can say there are two threads.The main thread,however remains the dominating one ,returning from main() causes the termination of all threads in the process.

nikita mullick
  • 97
  • 2
  • 11
  • A detached thread can outlive the main function terminating. This isn't the default but calling `pthread_detach()` would make it so. – John Mar 04 '18 at 09:59