Saturday, July 21, 2012

Implementation difference between a Linux process and a thread?

Difference between running a thread and a process is that when you are running a thread some data-structures are shared across the thread. For doing the same we will need IPC.

According to a nice post I found online here is the explanation:
inux uses a 1-1 threading model, with (to the kernel) no distinction between processes and threads -- everything is simply a runnable task. *
On Linux, the system call clone clones a task, with a configurable level of sharing, among which are:
  • CLONE_FILES: share the same file descriptor table (instead of creating a copy)
  • CLONE_PARENT: don't set up a parent-child relationship between the new task and the old (otherwise, child's getppid() = parent's getpid())
  • CLONE_VM: share the same memory space (instead of creating a COW copy)
fork() calls clone(least sharing) and pthread_create() calls clone(most sharing). **