Thread: thread and fork()

  1. #1
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002

    thread and fork()

    what's different between thread and fork( ) (or vfork( )) and their usage for programming in real life?
    which one could be used in which situation?
    I did read several posts, but still not clear.

    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  2. #2
    Join Date
    Nov 2003
    A process is a container for execution one or more threads. A process has to have at least one execution thread.

    fork() creates a process out of the old process, bringing along all of the threads. It takes a snapshot of all the variables, program counter, etc, and creates a new process with the same
    program counter, data, and code set. The forked process has a new process context, outside of the old one.

    A new thread remains inside the process context.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  2. What happens a thread calls fork()?
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 09-11-2008, 08:10 AM
  3. fork a child or create a thread?
    By zhoufanking in forum C Programming
    Replies: 3
    Last Post: 06-21-2008, 03:48 AM
  4. fork() inside a thread
    By rpalmer in forum C Programming
    Replies: 3
    Last Post: 05-25-2007, 02:29 AM
  5. problems with fork
    By raja9911 in forum C Programming
    Replies: 2
    Last Post: 02-03-2006, 07:48 AM