On Wed, Feb 27, 2008 at 3:14 PM, JM Ibanez <[EMAIL PROTECTED]> wrote: > > so fork() is cheap and switching between processes is also cheap.
both are expensive.. you are confused between process creation and thread creation as well as context switching between the two... fork() is expensive because resources owned by the parent process are duplicated to the child process... modern operating systems (and that includes linux) used a technique called copy-on-write (COW)... which avoids a copy of the parent's data space to the child until the child needs its own copy... but regardless of this optimization technique... fork is still expensive and much expensive compare to threads.. threads are sometime called as lightweight processes because instead of duplicating the parent's resources.. it shared instead...thus thread is pretty much cheaper than fork.. there is another similar function to a thread which is vfork()... ill give you this as an excercise to differentiates the three functions fork(), vfork() and a thread.. context switching is also expensive both for process and thread because of the fact that it requires restoring and storing the state of a CPU...as much as possible if you can minimize context switching to avoid excessive switching (hint: jiffies)... much better but it really depends on your applications and needs... but of course context switching time of a thread is faster than a process due to less CPU's state overhead of a thread... fooler. _________________________________________________ Philippine Linux Users' Group (PLUG) Mailing List plug@lists.linux.org.ph (#PLUG @ irc.free.net.ph) Read the Guidelines: http://linux.org.ph/lists Searchable Archives: http://archives.free.net.ph