1.) Five threads are created by a process with PID 10. Name three entities that are unique to threads (i.e. each thread has its own 'copy' potentially different from the other ones of other threads.)
2.) Five threads are created by a process with PID 10. Each one of the threads have threadIDs (TID) 11, 12, 13, 14, and 15 respectively. What is the value Linux(Unix) of getpid() returned when thread with TID 11 is issuing the call?
3.) process with PID 10 is creating five threads using thread_create(). How many threads of execution are there after the creation of those threads, assuming they have all been created successfully and all are still running ? process with PID 10 is creating five threads using thread_create(). How many threads of execution are there after the creation of those threads, assuming they have all been created successfully and all are still running ?
Please find the requested answers below.
Please provide your feedback
Thanks and Happy learning!
1) A thread is a light weight process. Each thread created by a process will have below unique entities
a. Thread ID
b. Stack(for storing local variables, return values etc..)
c. Saved registers
d. Stack pointer
e. instruction pointer
f. Signal mask
g. Scheduling priority information
2) As a thread is a light weight process, each thread lives within the same process. That means if a process with PID 10 creates five threads then all thos five threads are part of the same process(ie , process ID will be same for all those five threads but each thread will have ots own thread ID). So if the thread with TID calls the getpid() function then it will return the same process Id of the process which created this thread. That means the Thread id printed by getpid() will be 10(ie PID of the parent process which created this thread).
3) If the process with PID 10 creates 5 threads, then there will be total six threads of execution. When a process starts it will have a single main thread(ie each process is considered to have a single main thread). Now when the process/main thread creates new 5 threads, there will be total 6 threads. That are the main thread plus the newly created 5 threads.
Get Answers For Free
Most questions answered within 1 hours.