Quote:
Originally Posted by manohar
I have doubt regarding cpu sharing between process and threads.
|
Process is a collection of resources like memory et cetera, and one or more threads. Thread is the thing that executes code, the thing that actually uses CPU time. A process does not.
When you run a program that does not do any thread-related stuff at all, you actually get a process which has one thread. If the program creates new threads, they are just like the original thread. (The threading library may create extra structures or do some internal tricks, but those are implementation details that do not really matter.)
In fact, there is no way to create a process without any threads. This is why people talking about a single-threaded process usually talk about the process only; the one thread is always implied, and does not need to be explicitly mentioned. (The one case, a "zombie process", happens when a process dies but no one cares (yet). The process identifiers and the exit status is kept, but everything else about the process is released. So even zombies are not really processes without threads, they're more like the remains of a process that has not completely died yet.)
Quote:
Originally Posted by manohar
In my program iam creating 4threads=> 1 process+4 threads.
|
If you create four threads, e.g. by calling
pthread_create() four times, you'll have five threads total. You can alter their relative priorities via e.g.
pthread_setschedprio(), but by default, they are all equal, and get equal CPU time.
Some operating system kernels and/or threading libraries may adjust the priorities internally (temporarily) to ensure correct behaviour, or to optimize overall CPU use, so you cannot expect them to get
exactly the same share.