From f3c1232c5984a540c33841694469febbe951e7a8 Mon Sep 17 00:00:00 2001 From: mdavisprog Date: Thu, 12 Aug 2021 20:36:23 -0700 Subject: Add OS::is_process_running function. Adds the is_process_running function to the native OS class and exposes it to script. This is implemented on Windows and Unix platforms. A stub is provided for other platforms that do not support this function. Documentation is updated to reflect new API function. --- drivers/unix/os_unix.cpp | 9 +++++++++ drivers/unix/os_unix.h | 1 + 2 files changed, 10 insertions(+) (limited to 'drivers/unix') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 12e2113364..52a4d538e1 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -412,6 +412,15 @@ int OS_Unix::get_process_id() const { return getpid(); } +bool OS_Unix::is_process_running(const ProcessID &p_pid) const { + int status = 0; + if (waitpid(p_pid, &status, WNOHANG) != 0) { + return false; + } + + return true; +} + bool OS_Unix::has_environment(const String &p_var) const { return getenv(p_var.utf8().get_data()) != nullptr; } diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 6116574528..a1ed4bd501 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -76,6 +76,7 @@ public: virtual Error create_process(const String &p_path, const List &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override; virtual Error kill(const ProcessID &p_pid) override; virtual int get_process_id() const override; + virtual bool is_process_running(const ProcessID &p_pid) const override; virtual bool has_environment(const String &p_var) const override; virtual String get_environment(const String &p_var) const override; -- cgit v1.2.3