Everywhere: Replace some uses of fork/exec with posix_spawn

It's less code, and it's potentially more efficient once
posix_spawn is a real syscall.
This commit is contained in:
Nico Weber 2020-06-28 13:40:10 -04:00 committed by Andreas Kling
parent 301ac3c7e5
commit 12cbc4ad0d
Notes: sideshowbarker 2024-07-19 05:19:53 +09:00
11 changed files with 65 additions and 101 deletions

View file

@ -35,6 +35,7 @@
#include <LibGUI/Painter.h>
#include <LibGUI/Window.h>
#include <LibGfx/Palette.h>
#include <spawn.h>
#include <stdio.h>
enum class GraphType {
@ -106,14 +107,10 @@ private:
{
if (event.button() != GUI::MouseButton::Left)
return;
pid_t pid = fork();
if (pid < 0) {
perror("fork");
} else if (pid == 0) {
execl("/bin/SystemMonitor", "SystemMonitor", nullptr);
perror("execl");
ASSERT_NOT_REACHED();
}
pid_t child_pid;
const char* argv[] = { "SystemMonitor", nullptr };
if ((errno = posix_spawn(&child_pid, "/bin/SystemMonitor", nullptr, nullptr, const_cast<char**>(argv), environ)))
perror("posix_spawn");
}
static void get_cpu_usage(unsigned& busy, unsigned& idle)