0

Now I'm writting a C program on linux system.I want to print the call trace information on cpu, just like what dump_stack() does in kernel space or what command echo t > /proc/sysrq-trigger shows.

I've found some ways but they all need to be used in kernel space.

I also tried system("echo t > /proc/sysrq-trigger") and it finally shows that I can't simply do so.

sh: /sys/sysrq-trigger: Permission denied

So are there any solutions?

  • 1
    Does this answer your question? [print call stack in C or C++](https://stackoverflow.com/questions/3899870/print-call-stack-in-c-or-c) –  Aug 18 '21 at 09:32
  • @dratenik ```backstrace``` seems not suits my situaion. For ```backstrace``` can only print the call trace of this function, while I need to print the all the cpu like what ```echo t > /proc/sysrq-trigger``` does. – NotMe1993 Aug 18 '21 at 11:18
  • Ah, you want exactly what sysrq-t does. If you are prepared to modify the kernel, you could make a character device that lets you invoke dump_stack. Alternatively, give your user sudo rights and invoke the write under sudo. Or embed the `system("echo t > /proc/sysrq-trigger")` in a separate binary and make it setuid. –  Aug 18 '21 at 11:25

0 Answers0