Now I'm using function like this:
void print_trace() {
char pid_buf[30];
sprintf(pid_buf, "%d", getpid());
char name_buf[512];
name_buf[readlink("/proc/self/exe", name_buf, 511)]=0;
int child_pid = fork();
if (!child_pid) {
execlp("gdb", "gdb", "-batch", "-n", "-ex", "set pagination off", "-ex", "thread apply all bt full", name_buf, pid_buf, NULL);
abort(); /* If gdb failed to start */
} else {
wait(child_pid);
}
}
And I see details of print_trace in the output. Also I can't turn off pagination because I can execute only 1 command.
How this function can be improved?