/** * @file Process.h * @author apio (cloudapio.eu) * @brief Functions to manipulate processes. * * @copyright Copyright (c) 2023, the Luna authors. * */ #pragma once #include #include #include namespace os { /** * @brief An object representing a process. */ class Process { public: /** * @brief Create a new process, which is an identical copy of the current one. * * @return Result The child's process ID in the parent process, and 0 in the child process. */ static Result fork(); /** * @brief Replace the current process's executable with another one. * * @param path The new executable's path. * @param args The argument list to pass to the new executable. * @param search_in_path Determines whether to search in the system binary directories if path is just a name. * @return Result Always an error, as this function does not return on success. */ static Result exec(StringView path, Slice args, bool search_in_path = true); /** * @brief Replace the current process's executable with another one. * * @param path The new executable's path. * @param args The argument list to pass to the new executable. * @param search_in_path Determines whether to search in the system binary directories if path is just a name. * @return Result Always an error, as this function does not return on success. */ static Result exec(StringView path, Slice args, bool search_in_path = true); /** * @brief Replace the current process's executable with another one. * * @param path The new executable's path. * @param args The argument list to pass to the new executable. * @param env The environment to pass to the new executable, instead of the current environment. * @param search_in_path Determines whether to search in the system binary directories if path is just a name. * @return Result Always an error, as this function does not return on success. */ static Result exec(StringView path, Slice args, Slice env, bool search_in_path = true); }; }