process.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2012-2018 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "core/strings/types.h"
  7. namespace crown
  8. {
  9. /// ProcessFlags
  10. ///
  11. /// @ingroup Core
  12. struct ProcessFlags
  13. {
  14. enum Enum
  15. {
  16. STDIN_PIPE = 1 << 0, ///< Create stdin pipe.
  17. STDOUT_PIPE = 1 << 1, ///< Create stdout pipe.
  18. STDERR_MERGE = 1 << 2 ///< Merge stderr with stdout.
  19. };
  20. };
  21. /// Process.
  22. ///
  23. /// @ingroup Core
  24. struct Process
  25. {
  26. CE_ALIGN_DECL(16, u8 _data[32]);
  27. ///
  28. Process();
  29. ///
  30. ~Process();
  31. /// Spawns the process described by @a argv with the given @a flags.
  32. /// Returns 0 on success, non-zero otherwise.
  33. s32 spawn(const char* const* argv, u32 flags = 0);
  34. /// Returns whether the process has been spawned
  35. /// due to a previous successful call to spawn().
  36. bool spawned();
  37. /// Focefully terminates the process.
  38. /// On Linux, this function sends SIGKILL.
  39. void force_exit();
  40. /// Waits synchronously for the process to terminate and returns its exit code.
  41. s32 wait();
  42. ///
  43. char* fgets(char* data, u32 len);
  44. };
  45. } // namespace crown