Files
ladybird/Libraries/LibWebView/ProcessManager.h
ayeteadoe 433ff624b8 LibWebView: Abstract process exit monitoring into ProcessMonitor
There is no direct equivalent to SIGCHILD on Windows. The closest we
can get is monitoring a specific process, given a known pid. On Unix
there is no single solution to be able to do that in LibCore's
EventLoopImplementationUnix. For Linux there's a SYS_pidfd_open syscall
that can integrate into poll(), but on macOS a kqueue would be needed.
Given macOS uses EventLoopImplementationUnix for the headless view
implementation, we currently can't create a fully cross-platform
abstaction at the Event Loop level to match what Windows needs to do.

ProcessMonitor's purpose is to abstract away the Unix vs Windows
behaviour avoiding more inlined ifdef soup in ProcessManager.
2026-04-12 16:08:07 +02:00

50 lines
1.1 KiB
C++

/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/JsonValue.h>
#include <AK/Types.h>
#include <LibCore/Platform/ProcessStatistics.h>
#include <LibThreading/Mutex.h>
#include <LibWebView/Forward.h>
#include <LibWebView/Process.h>
#include <LibWebView/ProcessMonitor.h>
#include <LibWebView/ProcessType.h>
namespace WebView {
WEBVIEW_API ProcessType process_type_from_name(StringView);
WEBVIEW_API StringView process_name_from_type(ProcessType type);
class WEBVIEW_API ProcessManager {
AK_MAKE_NONCOPYABLE(ProcessManager);
public:
ProcessManager();
void add_process(Process&&);
Optional<Process> remove_process(pid_t);
Optional<Process&> find_process(pid_t);
#if defined(AK_OS_MACH)
void set_process_mach_port(pid_t, Core::MachPort&&);
#endif
void update_all_process_statistics();
JsonValue serialize_json();
Function<void(Process&&)> on_process_exited;
private:
Core::Platform::ProcessStatistics m_statistics;
HashMap<pid_t, Process> m_processes;
ProcessMonitor m_process_monitor;
Threading::Mutex m_lock;
};
}