-
February 2nd, 2007, 07:22 AM
#1
Fork Vs Thread
Hello firends!
Is it right compare between Thread and Fork:
Someone told me this in this subject:
1. fork()
Note that this only works on UNIX-like systems (like Linux). fork() is a library function which, when called, copies the entire process (including all variables) into a second process. Anything after the fork() call is therefore executed twice. fork() returns 0 to new process (the child) and the PID of the child to the calling process (the parent). Note that this is different from threads, because two seperate processes are run. This approach is sometimes used in web servers, so that a new process ifs forked for every client. This is easy to program, but inefficient, as you've got a new process for every client. Interaction between two of those processes is really hard (you'd have to use an intermediate file or something).
2. Threads
As far as I know, the Windows API supports threads instead of fork. When creating a thread in WinAPI, you call the CreateThread function (I'm not certain, I don't know too much about it), and you pass it a function pointer to the function you want the thread to execute
May you compare thread and fork?It means in Linux we don't use thread?
-
February 2nd, 2007, 07:59 AM
#2
Re: Fork Vs Thread
In Linux you use threads, see POXIS Thread for more information.
-
February 6th, 2007, 12:10 AM
#3
Re: Fork Vs Thread
Thread is more effective in memory management because it uses the same
memory block of parent process instead of creating new memory block to
run new process. But in *NIX environment, it is not as easy as MS-Win
environment to use thread.
-
February 6th, 2007, 04:17 PM
#4
Re: Fork Vs Thread
But in *NIX environment, it is not as easy as MS-Win
environment to use thread.
Actually only in non-Posix compliant implementations of *NIX, which (thankfully) are rather rare these days....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
February 7th, 2007, 03:33 AM
#5
Re: Fork Vs Thread
well correct me if i am wrong, unix systems always favor processes than threads maybe becaus e of the fact that creating/forking a process is very fast in unix.. i once created a PHP script server (somekind of com+) that manages requests from the web, i ended up forking processes because i could not find any support on threads. i've took advantage of of using the System V IPC to communicate between processes. so far it is working perfectly
Busy
-
February 11th, 2007, 12:21 AM
#6
Re: Fork Vs Thread
Well, on unix systems the effectiveness of threads vs. processes is about the same (in contrast to windows where processes are pretty expensive), In the end it boils down to what you need to do - threads share the same memory, but it mean locking management, making functions reentrant etc.
-
February 16th, 2007, 01:18 PM
#7
Re: Fork Vs Thread
threads are definitly faster than running a second proccess no doubts.
its not really hard to make threads, forking is alot harder.
for those wich have difficult threads, dont bother...?
-
February 20th, 2007, 01:40 PM
#8
Re: Fork Vs Thread
Hi For a C code in Linux i want to reset the stack size of the main() that is only one thread is there in the process. Any pointers on that.
For any function do we have to use that function inside the main i.e we are resetting the stacksize of that thread or process inside that process or thread?
a snippet
main ()
main ( int argc, char **argv )
{
int rc = 0;
pthread_attr_t threadAttr;
pthread_attr_init( &threadAttr );
pthread_attr_setstacksize( &threadAttr, 3584);
}
would it work in setting the stacksize of main to 3584 kbytes
-
January 20th, 2010, 03:44 PM
#9
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|