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
There are 2 stacks because there are 2 CPU execution contexts. The user mode stack will cater to your program with respect to creating stack frames for functions, local variables, return addresses etc. When the CPU switches context to kernel mode, for instance during system call execution, it needs access to kernel memory and data structures and so switches to using it's kernel stack. And yes, Unix I believe uses a per process kernel stack.