Is there a way to print stacktrace of all threads without attaching GDB?
Or is there a command which I can use as gdb batch mode to print stacktrace of all threads?
As in linux All threads are essentially Light weight processes , they get individual LWP PIDs. you can dump the status of these by using a ps or top based script or echoing the w in /proc/sysrq-trigger. This will give you the I/O state of the threads in the /var/log/messages.
This won't give you the complete stack trace though . but its a good way to debug the thread states on periodical intervals.
you can also explore whats current scheduler state by looking into /proc/sched_debug to see which tasks are getting scheduled and so on .