What is the need of using two different stacks in same program? How does trap change the current stack of program from user stack to kernel stack? How does it come back to user
One of the reasons for having a separate kernel stack is that the kernel needs a place to store information where user-mode code can't touch it. That prevents user-mode code running in a different thread/process from accidentally or maliciously affecting execution of the kernel.