Whether should i use processes or threads in Linux?

While designing any system usually we might confuse between thread and process usage . We think should we use thread or process for our requirement. Which will be the best choice.?


So Here are some guidelines to help you……



  • All threads inside a program always run from the same executable binary. Where a child process , may run a from different executable binary by calling an exec function.
  • If one process crashes or has a buffer overrun, it does not affect any other process at all, whereas if a thread crashes, it takes down all of the other threads in the process because threads share the same virtual memory space and other resources.
  • Threads should be used for programs that need fine-grained parallelism. For example, if a problem can be broken into multiple, nearly identical tasks, threads may be a good choice. Processes should be used for programs that need coarser parallelism.
  • Sharing data among threads is quite easy because threads share the same memory. Sharing data among processes needs to  the use of IPC mechanisms which is quite complex.
  •  Processes are more heavy-weight than threads, and have a higher start up and shutdown cost. Interprocess communication (IPC) is also harder and slower than inter-thread communication.


Note : There is also some discussion about saying t in Windows processes are heavy and expensive compared to threads, and in Linux the difference is much smaller.


hey I am an Artist who love to write code...! Well I am an EC graduate From Ganpat University and now i am working as Embedded software engineer in one private firm.. find me at here JigAr Patel

More Posts - Website - Twitter - Facebook

2 Comments to “Whether should i use processes or threads in Linux?”

  • Rasmiranjan Nayak February 1, 2012 at 9:00 am

    Jigar:- What is the difference between exec() and clone()? I am novice to UNIX..

    • JIGAR PATEL February 2, 2012 at 1:55 pm

      exec() : The exec call is a way to basically replace the entire current process with a new program. It loads the program into the current process space and runs it from the entry point.

      clone() : to understand this you need to understand the concept of fork()
      see fork call basically makes a duplicate of the current process, identical in almost every way (not everything is copied over, for example, resource limits in some implementations but the idea is to create as close a copy as possible).

      where clone is something differ
      Clone, as fork, creates a new process. but these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers.So here IPC calls make easily

      i hope you get it but dont worry very soon i will write one article for clearing all such confusion about those system call …right now i am also working with such things..!!!

Post comment

Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

Find us on Facebook

Find us on stackoverflow


Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link