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.
You may like to read this also....
2 Comments to “Whether should i use processes or threads in Linux?”
Post comment
Search in this website
our sponsors
latest comments
- kamal9211 on Top/Best C/C++ IDE for Windows & Linux
- kamlesh khot on Structure of a C-Program in Memory | How Heap,Stack,Data and Code segments are stored in memory?
- vamsi on List of all standard version of c language
- c programme language on Implementation limitation of c programming language
- codebreaker on How to access/unblock songs.pk in india?
Find us on Facebook
Top Authors
Find us on stackoverflow
Polls
Loading ...
My Bookmarks
- Audio/video Recorder & player application based on MATLAB
- check dependency of your binary
- defination of all standard c programming language function
- Great Question-Answer on c programming
- know what your c code means
- Limition of c programming language
- List of all version of c programming language
- Online c compiler
- php freelancing work
- some more stuff on C programming language
- Volatile Keyword in Embedded System
- Write Android application in c language
Jigar:- What is the difference between exec() and clone()? I am novice to UNIX..
Rasmiranjan Nayak recently posted..Volatile Keyword in Embedded System
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..!!!
JIGAR PATEL recently posted..Whether should i use processes or threads in Linux?