process.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <functional>
  3. #include <list>
  4. #include <string>
  5. #include <vector>
  6. #include "base/define.h"
  7. #include "util/strutils.h"
  8. namespace ylib
  9. {
  10. namespace process
  11. {
  12. // 取进程路径
  13. std::string getpath(uint32 process_id);
  14. /*进程信息*/
  15. struct proc_info
  16. {
  17. std::string path()
  18. {
  19. if (__filepath.empty())
  20. __filepath = strutils::replace(ylib::process::getpath(pid), '\\', '/');
  21. return __filepath;
  22. }
  23. std::string __filepath;
  24. std::string name;
  25. uint32 parent_pid = 0;
  26. uint32 pid = 0;
  27. };
  28. // 创建进程
  29. bool create(const std::string& filepath, const std::string& working_directory = "", const std::vector<std::string>& args = {}, bool wait_close = false, bool show_window = true, int* return_code = nullptr, size_t* pid = nullptr);
  30. // 销毁进程
  31. bool destory(uint32 process_id);
  32. // 系统进程列表
  33. std::list<ylib::process::proc_info> list();
  34. // 是否存在
  35. std::vector<size_t> exist(const std::string& filepath);
  36. bool exist(size_t pid);
  37. #ifdef _WIN32
  38. // 检测多开
  39. bool already_running(const std::string& name);
  40. // 设置为启动
  41. bool running(const std::string& name);
  42. #endif
  43. }
  44. }