Process.cpp 751 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/String.h>
  7. #include <LibCore/Process.h>
  8. #include <errno.h>
  9. #include <spawn.h>
  10. #include <unistd.h>
  11. #ifdef __serenity__
  12. # include <serenity.h>
  13. #endif
  14. namespace Core {
  15. pid_t Process::spawn(StringView path)
  16. {
  17. String path_string = path;
  18. pid_t pid;
  19. char const* argv[] = { path_string.characters(), nullptr };
  20. if ((errno = posix_spawn(&pid, path_string.characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
  21. perror("Process::spawn posix_spawn");
  22. } else {
  23. #ifdef __serenity__
  24. if (disown(pid) < 0)
  25. perror("Process::spawn disown");
  26. #endif
  27. }
  28. return pid;
  29. }
  30. }