P2L4 Thread Design Considerations - Tasks in Linux Flashcards

1
Q

Define a ‘task’

A
  • An abstraction that represents an execution context
  • The execution context of a kernel level thread
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A single-threaded process will have _____ task, and a multithreaded process will have _____ tasks.

A

A single-threaded process will have one task, and a multithreaded process will have many tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False?

Linux has one continuous process control block.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe how Linux creates a new task

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the arguments to the function clone that creates a new task?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False

‘fork’ in Linux is basically implemented by clone with all sharing flags cleared.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A multi-threaded process forks a new process. Will this process be single or multi-threaded?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly