0

If I have a program written as follow:

void main() {

    //some code
    printf(" hi \n");
   
    checkpoint1(); <-------- checkpoint1

    //some Code with no dependency on other program/task or HW IO

    checkpoint2(); <-------- checkpoint2

    printf(" test end \n");

    //some code

    return;

}

is there any Linux API or a way in Linux that I can use to find out what task and process (including background programs, daemons and services) are running on all cores in between the checkpoints and for how long they are running ?

Edit: basically the problem is I have a program running in Linux where between the 2 checkpoint randomly will take too long to complete, and the program is not depending on other task/process or hardware IO, so I would like to debug this issue.

would be nice if there is a solution with detail or API or websites links to the solution.

  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Feb 20 '23 at 05:56
  • Not really. You could look at the output of `ps`, or scan the `/proc` file system, but neither of those is instantaneous. What is the `printf("some programs\n");` line meant to represent, though? If you write some code there (other than just a `printf()` statement) that runs other programs, then you know what's going on, for the most part. It could be tricky if you use something that creates a thread or process without you realizing it. But there still isn't an easy way to find out what was going on. – Jonathan Leffler Feb 20 '23 at 06:09
  • @JonathanLeffler hi the original program has no printf, thanks for pointing out i'll edit the post. – Henry Leong Feb 20 '23 at 06:14
  • 1
    You can use `strace` to see all syscalls made by your process, it may be useful in your situation – qrdl Feb 20 '23 at 09:30
  • Yes, that's what `perf` tool is using. Run your code in between under `perf` and you will see everything you need. – 0andriy Feb 20 '23 at 10:37

0 Answers0