From 1380d03a42da510cf08be8a024b3e65508a3eeab Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 27 Feb 2026 10:16:51 -0500 Subject: [PATCH] time_stats: Replace fork+exec with posix_spawn. --- src/bin/debug/time_stats/timing_analysis.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/bin/debug/time_stats/timing_analysis.cpp b/src/bin/debug/time_stats/timing_analysis.cpp index 01ee2e490e..4b3f0bdf75 100644 --- a/src/bin/debug/time_stats/timing_analysis.cpp +++ b/src/bin/debug/time_stats/timing_analysis.cpp @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -57,22 +58,16 @@ get_usage_infos(thread_info* infos) static pid_t run_child(int argc, const char* const* argv) { - // fork - pid_t child = fork(); - if (child < 0) { - fprintf(stderr, "Error: fork() failed: %s\n", strerror(errno)); - exit(1); - } - - // exec child process - if (child == 0) { - execvp(argv[0], (char**)argv); + pid_t child; + int status = posix_spawnp(&child, argv[0], NULL, NULL, (char**)argv, NULL); + if (status != 0) { + fprintf(stderr, "Error: spawn failed: %s\n", strerror(status)); exit(1); } // wait for child int childStatus; - while (wait(&childStatus) < 0); + while (waitpid(child, &childStatus, 0) < 0); return child; }