P2L4 Thread Design Considerations - Tasks in Linux Flashcards
Define a ‘task’
- An abstraction that represents an execution context
- The execution context of a kernel level thread
A single-threaded process will have _____ task, and a multithreaded process will have _____ tasks.
A single-threaded process will have one task, and a multithreaded process will have many tasks.
A task is identified by its ____________
If we have a single threaded process the id of the task and the id of the process will______________
If we have a multithreaded process, each task will have a _________ pid.
If we have a multithreaded process, the process as a whole will be identified by ___________________________
A task is identified by its pid_t pid.
If we have a single threaded process the id of the task and the id of the process will be the same.
If we have a multithreaded process, each task will have a different pid.
If we have a multithreaded process, the process as a whole will be identified by the pid of the first task that was created.
True or False?
Linux has one continuous process control block.
False
Linux never had one continuous process control block. Instead, the process state was always maintained through a collection of data structures that pointed to each other. We can see some of the references in the task in struct mm_struct *mm and struct files_struct *files.
Describe how Linux creates a new task
clone
To create a new task, Linux supports an operation called clone. It takes a function pointer and an argument (similar to pthread_create) but it also takes an argument sharing_flags which denotes which portion of the state of a task will be shared between the parent and child task.
What are the arguments to the function clone that creates a new task?
- function
- stack_ptr
- sharing_flags - which portion of the state of a task will be shared between the parent and child task.
When all set –> like creating a thread - sharing everything
When none set –> like forking a new process - sharing almost nothing
- args
True or False
‘fork’ in Linux is basically implemented by clone with all sharing flags cleared.
True
The native implementation of threads in Linux is the Native POSIX Threads Library (NPTL). This is a ______ model, meaning that there is a _______ level task for each ____ level thread.
This implementation replaced an earlier implementation LinuxThreads, which was a __________ model.
The native implementation of threads in Linux is the Native POSIX Threads Library (NPTL). This is a ______ model, meaning that there is a kernel level task for each user level thread. This implementation replaced an earlier implementation LinuxThreads, which was a many-to-many model.
A multi-threaded process forks a new process. Will this process be single or multi-threaded?
Single threaded process forks a new process -> copy with same address space
Multi-threaded process forks a new process -> single threaded - will only contain a portion of the parent’s address space