Skip to content
Advertisement

gmon.out is not created when executable forks another executable

I am using gprof for profiling. But gmon.out is not created when I fork another executable inside the main executable which is compiled with option -pg. Any idea how to resolve it.

Advertisement

Answer

But gmon.out is not created when I fork another executable

It probably does. It simply has the same name as all the other gmon.out files. They just silently overwrite each other.

GNU, in all its infinite wisdom, recommends that each child process that you want to profile be executed in its own current directory. Use mkdir and chdir in your code as needed. Since gmon.out is written out as the process finishes, it is only necessary to chdir before calling exit.

I also recommend looking at valgrind. Among other nice things, it has its output files named something.somethingelse.$PID.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement