TATA Consultancy Services Interview Question
Country: India
1.
Linux newbie...so, take this with a grain of salt. I looked into Linux source code and here is what I see. I looked into the source and then I understood Stan's comment. But, posting for ref.
55 struct thread_info {
56 struct task_struct *task; /* main task structure */
57 __u32 flags; /* low level flags */
58 __u32 status; /* thread synchronous flags */
59 __u32 cpu; /* current CPU */
60 mm_segment_t addr_limit;
61 unsigned int sig_on_uaccess_error:1;
62 unsigned int uaccess_err:1; /* uaccess failed */
63 };
If the task ptr in is not NULL, then it means that this is a thread. If NULL, it is a process.
Forgot the second part of the question....I posted a link to an ITANIUM programmers manual and the post got killed :-(
The thread context is usually lighter than the process context. Hence the speed difference.
For example, thread context is only the general purpose cpu registers. Floating point registers, memory management info (like region table info in Itanium), etc are not saved on a thread context switch...they *HAVE* to be saved if we were to switch processes and new ones restored. Look at any chipsets system programmer's manual for details.
As I know difference for kernel with lwp and process - task_info structure for lwp. If this structure exists - it is lwp. For get less overhead kernel use mechanism as know as page fault. Restore context will be full (cpu registers).
- Stan P. March 25, 2016