SlideShare utilise les cookies pour améliorer les fonctionnalités et les performances, et également pour vous montrer des publicités pertinentes. Si vous continuez à naviguer sur ce site, vous acceptez l’utilisation de cookies. Consultez nos Conditions d’utilisation et notre Politique de confidentialité.
SlideShare utilise les cookies pour améliorer les fonctionnalités et les performances, et également pour vous montrer des publicités pertinentes. Si vous continuez à naviguer sur ce site, vous acceptez l’utilisation de cookies. Consultez notre Politique de confidentialité et nos Conditions d’utilisation pour en savoir plus.
2. Process State
3. Process Control Block
5. Multithreading Model
6. Linux Threads
A process is running instance of a program.
Process memory is divided into four sections
1. The text section comprises the compiled program code, read
in from non-volatile storage when the program is launched.
2. The data section stores global and static variables, allocated
and initialized prior to executing main.
3. The heap is used for dynamic memory allocation, and is
managed via calls to new, delete, malloc, free, etc.
4. The stack is used for local variables. Space on the stack is
reserved for local variables when they are declared ( at
function entrance or elsewhere, depending on the language ),
and the space is freed up when the variables go out of scope.
Note that the stack is also used for function return values, and
the exact mechanisms of stack management may be language
Processes may be in one of 5 states.
New - The process is in the stage of being created.
Ready - The process has all the resources available that it needs to run, but the CPU is not
currently working on this process's instructions.
Running - The CPU is working on this process's instructions.
Waiting - The process cannot run at the moment, because it is waiting for some resource to
become available or for some event to occur. For example the process may be waiting for
keyboard input, disk access request, inter-process messages, a timer to go off, or a child
process to finish.
Terminated - The process has completed.
Process Control Block
For each process there is a Process Control Block, PCB, which stores the following types of
Process State - Running, waiting, etc.
Process ID, and parent process ID.
CPU registers and Program Counter - These need to be saved and restored when
swapping processes in and out of the CPU.
CPU-Scheduling information - Such as priority information and pointers to scheduling
Memory-Management information - E.g. page tables or
Accounting information - user and kernel CPU time consumed,
account numbers, limits, etc.
I/O Status information - Devices allocated, open file tables,
A thread is a basic unit of CPU utilization, consisting of a program counter, a stack,
and a set of registers, ( and a thread ID. )
Multi-threaded applications have multiple threads within a single process,
each having their own program counter, stack and set of registers, but sharing
common code, data, and certain structures such as open files.
Single threaded Process Multithreaded Process
There are two types of threads to be managed in a modern system:
User threads are supported above the kernel, without kernel support. These are the threads that
application programmers would put into their programs.
Kernel threads are supported within the kernel of the OS itself. All modern OSes support kernel level
threads, allowing the kernel to perform multiple simultaneous tasks and/or to service multiple kernel
system calls simultaneously.
In a specific implementation, the user threads must be mapped to kernel threads, using one of
the following strategies.
Many to One Model
One to One Model
Many to Many Model
Multithreading Model (cont.)
Linux and Windows from 95 to XP
Multithreading Model (cont.)
Many-To-Many two-tier model
IRIX, HP-UX, and Tru64 UNIX
Linux does not distinguish between processes and threads
The traditional fork( ) system call completely duplicates a process.
An alternative system call, clone( ) allows for varying degrees of sharing between the parent and child
tasks, controlled by flags such as those shown in the following table:
Calling clone( )with no flags set is equivalent to fork( ). Calling clone( ) with CLONE_FS,
CLONE_VM, CLONE_SIGHAND, and CLONE_FILES is equivalent to creating a thread, as all of
these data structures will be shared.
Linux implements this using a structure task_struct, which essentially provides a level of indirection to
task resources. When the flags are not set, then the resources pointed to by the structure are copied,
but if the flags are set, then only the pointers to the resources are copied, and hence the resources are
CLONE_FS File-system information is shared
CLONE_VM The same memory space is shared
CLONE_SIGHAND Signal handlers are shared
CLONE_FILES The set of open files is shared