Explain Linux Threads with Example.
1 Answer


Linux Threads:

  • Linux provides the fork() system call with the traditional functionality of duplicating a process.

  • Linux also provides the ability to create threads using the clone () system call. However, Linux does not distinguish between processes and threads.

enter image description here

  • Linux generally uses the term task—rather than process or thread—when referring to a flow of control within a program.

  • When clone 0 is invoked, it is passed a set of flags, which determine how much sharing is to take place between the parent and child tasks.


  • Example, if clone() is passed the flags CL0NE_FS, CLONEJM, CLONE_SIGHAND, and CLONE_FILES, the parent and child tasks will share the same file-system information , the same memory space, the same signal handlers, and the same set of open files.

enter image description here

  • Using clone () in this fashion is equivalent to creating a thread as described in this chapter, since the parent task shares most of its resources with its child task.

  • If none of these flags are set when clone () is invoked, no sharing takes place, resulting in functionality similar to that provided By the fork () system call.

  • A unique kernel data structure (specifically, struct task.struct) exists for each task in the system.

  • This data structure, instead of storing data for the task, contains pointers to other data structures where these data are stored—for example, data structures that represent the list of open files, signal-handling information, and virtual memory.

Please log in to add an answer.