process.h 1.0 KB

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