And to avoid the need for a context switch when the

This preview shows page 27 - 33 out of 33 pages.

and to avoid the need for a context switch when the scheduler switches among processes in the same group. A new process is created in Linux by copying the attributes of the current process. A new process can be cloned so that it shares resources, such as files, signal handlers, and virtual memory. When the two processes share the same virtual memory, they function as threads within a single process via clone() system call. However, no separate type of data structure is defined for a thread. When the Linux kernel performs a switch from one process to another, it checks whether the address of the page directory of the current process is the same as that of the to-be-scheduled process. If they are, then they are sharing the same address space, so that a context switch is basically just a jump from one location of code to another location of code. Although cloned processes that are part of the same process group can share the same memory space, they cannot share the same user stacks. Thus the clone() call creates separate stack spaces for each process.
Image of page 27

Subscribe to view the full document.

28 Figure 4.10: Linux clone() system call flags 4.4.1 Linux Thread Life-Cycle Running: Corresponds to two states. A Running process is either executing or It is ready to execute. Interruptible: A blocked state, in which the process is waiting for an event, such as the end of an I/O operation, the availability of a resource, or a signal from another process. Uninterruptible: Another blocked state. The difference between the Interruptible state is that in this state, a process is waiting directly on hardware conditions and therefore will not handle any signals. Stopped: The process has been halted and can only resume by positive action from another process.
Image of page 28
29 (e.g., ) A process that is being debugged can be put into the Stopped state. Zombie: The process has been terminated but, for some reason, still must have its task structure in the process table. Figure 4.11: Linux Process/Thread Model 4.4.2 Native POSIX Thread Library (NPTL) Thread creation is done through clone() system call: clone() allows a child task to share the address space of the parent task (process) Linux refers to them as tasks rather than threads o In NPTL, all threads belong to a single process. NPTL threads are based on KSEs(kernel scheduling entities). A non-threaded process is also a KSE. A threaded process has more than one KSEs. All KSEs are scheduled by the kernel. o NPTL is based on fast mutual exclusion (futex) mechanism. o Not fully POSIX compliant o See the papers on OS course website about NPTL design and implantation. Figure 4.12: Linux Threads (1:1 Mapping)
Image of page 29

Subscribe to view the full document.

30 Figure 4.13: Thread creation by clone() system call
Image of page 30
31 Figure 4.14: Linux gettid() 5. Summary on Thread Implementations on various Operating Systems There are many different and incompatible implementations of threading. These include both kernel-level and user-level implementations. However, they often follow more or less closely the POSIX Threads interface.
Image of page 31

Subscribe to view the full document.

32 Kernel-level implementation examples Light Weight Kernel Threads (LWKT) in various BSDs M:N threading
Image of page 32
Image of page 33
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern